mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
fix: stop rendering if destroyed (#1748)
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user