fix: stop rendering if destroyed (#1748)

This commit is contained in:
Tobias Åström
2025-05-19 11:17:19 +02:00
committed by GitHub
parent 391612dec4
commit e3aab5a1ef
2 changed files with 25 additions and 12 deletions

View File

@@ -58,6 +58,7 @@ export { NebulaApp };
export default function boot({ app, context }) {
let resolveRender;
let destroyed = false;
const rendered = new Promise((resolve) => {
resolveRender = resolve;
});
@@ -105,7 +106,7 @@ export default function boot({ app, context }) {
delete cells[id];
},
add(component, unmount) {
(async () => {
return (async () => {
await rendered;
components.push(component);
componentsUnmount.push(unmount);
@@ -113,16 +114,18 @@ export default function boot({ app, context }) {
})();
},
remove(component) {
(async () => {
await rendered;
const ix = components.indexOf(component);
if (ix !== -1) {
componentsUnmount[ix]?.();
components.splice(ix, 1);
componentsUnmount.splice(ix, 1);
}
appRef?.current?.setComps(components);
})();
if (!destroyed) {
(async () => {
await rendered;
const ix = components.indexOf(component);
if (ix !== -1) {
componentsUnmount[ix]?.();
components.splice(ix, 1);
componentsUnmount.splice(ix, 1);
}
appRef?.current?.setComps(components);
})();
}
},
setMuiThemeName(themeName) {
(async () => {
@@ -141,6 +144,7 @@ export default function boot({ app, context }) {
})();
},
destroy() {
destroyed = true;
componentsUnmount.forEach((c) => {
c && c();
});

View File

@@ -42,9 +42,18 @@ export default function glue({
};
model.on('closed', unmount);
root.add(portal, unmount);
// Cannot use model.id as it is not unique in a given mashup
root.addCell(currentId, cellRef);
(async () => {
try {
await root.add(portal, unmount);
} catch (e) {
unmount();
onMount();
onError(e);
}
})();
return [unmount, cellRef];
}