Skip to content

Commit

Permalink
fix: use the newly introduced skipExisting plugin registration option
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Sep 15, 2020
1 parent d3ca986 commit 789c749
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -4,6 +4,9 @@ import { CircularProgress } from "@webiny/ui/Progress";

const globalState = { render: false, editor: false };

// Since these plugins are loaded asynchronously, and some overrides might've been registered
// already by the developer (e.g. in the main App.tsx file), we only register new plugins.
// In other words, if the plugin with a particular name already exists, we skip its registration.
export function EditorPluginsLoader({ children, location }) {
const [loaded, setLoaded] = useReducer(
(state, newState) => ({ ...state, ...newState }),
Expand All @@ -14,7 +17,9 @@ export function EditorPluginsLoader({ children, location }) {
// If we are on pages list route, import plugins required to render the page content.
if (location.pathname.startsWith("/page-builder/pages") && !loaded.render) {
const renderPlugins = await import("@webiny/app-page-builder/render/presets/default");
registerPlugins(renderPlugins.default());

// "skipExisting" will ensure existing plugins (with the same name) are not overridden.
registerPlugins(renderPlugins.default(), { skipExisting: true });

globalState.render = true;
setLoaded({ render: true });
Expand All @@ -30,7 +35,12 @@ export function EditorPluginsLoader({ children, location }) {
: null
].filter(Boolean)
);
registerPlugins(plugins.map(p => p.default()));

// "skipExisting" will ensure existing plugins (with the same name) are not overridden.
registerPlugins(
plugins.map(p => p.default()),
{ skipExisting: true }
);

globalState.editor = true;
globalState.render = true;
Expand Down

0 comments on commit 789c749

Please sign in to comment.