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

View File

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