Skip to content

Commit 6298cc6

Browse files
committed
fix: await loading of editor components
1 parent e32c447 commit 6298cc6

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

packages/decap-cms-app/src/init/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const editorComponents = {
5656
}),
5757
};
5858

59-
function registerWidgetsAndEditorComponents(config: CmsConfig) {
59+
async function registerWidgetsAndEditorComponents(config: CmsConfig) {
6060
const usedWidgets = new Set<string>();
6161
const usedEditorComponents = new Set<string>();
6262

@@ -71,22 +71,24 @@ function registerWidgetsAndEditorComponents(config: CmsConfig) {
7171
}
7272

7373
// Load and register all used editor components
74-
usedEditorComponents.values().map(async type => {
75-
const loader = editorComponents[type as keyof typeof editorComponents];
76-
if (loader) {
77-
// Don't override manually registered components...
78-
if (!cms.getEditorComponents().has(type)) {
79-
cms.registerEditorComponent(await loader());
80-
}
81-
} else {
82-
// Check if the component has been manually registered...
83-
if (!cms.getEditorComponents().has(type)) {
84-
throw new Error(
85-
`Unknown editor component "${type}". If this is a custom component, make sure to register it.`,
86-
);
74+
await Promise.all(
75+
[...usedEditorComponents].map(async type => {
76+
const loader = editorComponents[type as keyof typeof editorComponents];
77+
if (loader) {
78+
// Don't override manually registered components...
79+
if (!cms.getEditorComponents().has(type)) {
80+
cms.registerEditorComponent(await loader());
81+
}
82+
} else {
83+
// Check if the component has been manually registered...
84+
if (!cms.getEditorComponents().has(type)) {
85+
throw new Error(
86+
`Unknown editor component "${type}". If this is a custom component, make sure to register it.`,
87+
);
88+
}
8789
}
88-
}
89-
});
90+
}),
91+
);
9092

9193
// Collect widgets from editor components (like the "code" widget from the code-block)
9294
cms

0 commit comments

Comments
 (0)