Open platform to collect and prioritize feedback
enhancement: move react-toastify to its own bundle (#645)
Guilherme Oenning0a2c075a6044
diff --git a/app/pkg/web/testdata/basic.html b/app/pkg/web/testdata/basic.htmlindex 3342362b0..6148c34cd 100755--- a/app/pkg/web/testdata/basic.html+++ b/app/pkg/web/testdata/basic.html@@ -30,7 +30,7 @@- <div id="root"></div><div id="root-modal"></div>+ <div id="root"></div><div id="root-modal"></div><div id="root-toastify"></div><script id="server-data" type="application/json">diff --git a/app/pkg/web/testdata/props.html b/app/pkg/web/testdata/props.htmlindex 102083347..dba290fd5 100755--- a/app/pkg/web/testdata/props.html+++ b/app/pkg/web/testdata/props.html@@ -30,7 +30,7 @@- <div id="root"></div><div id="root-modal"></div>+ <div id="root"></div><div id="root-modal"></div><div id="root-toastify"></div><script id="server-data" type="application/json">diff --git a/app/pkg/web/testdata/tenant.html b/app/pkg/web/testdata/tenant.htmlindex 5a6d0d254..cdd95018e 100755--- a/app/pkg/web/testdata/tenant.html+++ b/app/pkg/web/testdata/tenant.html@@ -32,7 +32,7 @@- <div id="root"></div><div id="root-modal"></div>+ <div id="root"></div><div id="root-modal"></div><div id="root-toastify"></div><script id="server-data" type="application/json">diff --git a/app/pkg/web/testdata/user.html b/app/pkg/web/testdata/user.htmlindex 6861cb422..307365734 100755--- a/app/pkg/web/testdata/user.html+++ b/app/pkg/web/testdata/user.html@@ -30,7 +30,7 @@- <div id="root"></div><div id="root-modal"></div>+ <div id="root"></div><div id="root-modal"></div><div id="root-toastify"></div><script id="server-data" type="application/json">diff --git a/public/index.tsx b/public/index.tsxindex 1ac6f55ef..2c3fc28a2 100644--- a/public/index.tsx+++ b/public/index.tsx@@ -4,7 +4,6 @@ import { resolveRootComponent } from "@fider/router";import { Header, Footer } from "@fider/components/common";import { ErrorBoundary } from "@fider/components";import { classSet, Fider, actions, navigator } from "@fider/services";-import { ToastContainer, toast } from "react-toastify";import { IconContext } from "react-icons";import "@fider/assets/styles/main.scss";@@ -51,7 +50,6 @@ window.addEventListener("error", (evt: ErrorEvent) => {ReactDOM.render(<ErrorBoundary onError={logProductionError}><IconContext.Provider value={{ className: "icon" }}>- <ToastContainer position={toast.POSITION.TOP_RIGHT} toastClassName="c-toast" />{config.showHeader && <Header />}{React.createElement(config.component, fider.session.props)}{config.showHeader && <Footer />}diff --git a/public/services/notify.ts b/public/services/notify.tsindex 946fda020..59c6fb837 100644--- a/public/services/notify.ts+++ b/public/services/notify.ts@@ -1,9 +1,13 @@-import { toast } from "react-toastify";+const toastify = () => import(/* webpackChunkName: "toastify" */ "./toastify");-export const success = (message: string | JSX.Element) => {- toast.success(message);+export const success = (content: string | JSX.Element) => {+ return toastify().then(toast => {+ toast.success(content);+ });};-export const error = (message: string | JSX.Element) => {- toast.error(message);+export const error = (content: string | JSX.Element) => {+ return toastify().then(toast => {+ toast.error(content);+ });};diff --git a/public/services/toastify.tsx b/public/services/toastify.tsxnew file mode 100644index 000000000..b8105bac1--- /dev/null+++ b/public/services/toastify.tsx@@ -0,0 +1,27 @@+import React from "react";+import ReactDOM from "react-dom";++import { ToastContainer, toast, ToastContent, ToastOptions } from "react-toastify";+import "react-toastify/dist/ReactToastify.css";++let hasContainer = false;++const setup = () => {+ if (!hasContainer) {+ hasContainer = true;+ ReactDOM.render(+ <ToastContainer position={toast.POSITION.TOP_RIGHT} toastClassName="c-toast" />,+ document.getElementById("root-toastify")+ );+ }+};++export const success = (content: ToastContent, options?: ToastOptions) => {+ setup();+ toast.success(content, options);+};++export const error = (content: ToastContent, options?: ToastOptions) => {+ setup();+ toast.error(content, options);+};diff --git a/views/index.html b/views/index.htmlindex 6a53ada5c..eb7fd4ead 100644--- a/views/index.html+++ b/views/index.html@@ -3,7 +3,7 @@{{define "server-data"}}{{ . }}{{ end }}-{{define "content"}}<div id="root"></div><div id="root-modal"></div>{{end}}+{{define "content"}}<div id="root"></div><div id="root-modal"></div><div id="root-toastify"></div>{{end}}{{define "end-of-body"}}{{ if .__assets }}{{range .__assets.JS}}diff --git a/webpack.config.js b/webpack.config.jsindex 9775a2ece..916057c6e 100755--- a/webpack.config.js+++ b/webpack.config.js@@ -46,13 +46,9 @@ module.exports = {"tslib","marked","react-textarea-autosize",- "react-toastify","react-loadable","react-icons/lib"],- vendorCSS: [- "react-toastify/dist/ReactToastify.css"- ],},output: {path: __dirname + "/dist",@@ -67,8 +63,8 @@ module.exports = {}},performance: {- maxEntrypointSize: 389120 * maxSizeFactor, // 380 KiB. Should ideally be ~240 KiB- maxAssetSize: 256000 * maxSizeFactor, // 250 KiB+ maxEntrypointSize: 307200 * maxSizeFactor, // 300 KiB. Should ideally be ~240 KiB+ maxAssetSize: 184320 * maxSizeFactor, // 180 KiBhints: "error"},module: {