Clean partial editor mounts and failed refreshes
This commit is contained in:
1 parent
3da88510df
commit
d41eda7050
3 files changed
+39
-10
No files matched your search
@@ -31,8 +31,20 @@ export function mountBlockEditor(root: HTMLElement, options: MountEditorOptions)
|
||||
live.style.cssText =
|
||||
"position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0";
|
||||
root.append(live);
|
||||
const destroy = () => {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
generation++;
|
||||
try {
|
||||
cleanups.forEach((cleanup) => cleanup());
|
||||
} finally {
|
||||
cleanups = [];
|
||||
try { manager?.destroy(); } finally { live.remove(); }
|
||||
}
|
||||
};
|
||||
const refresh = () => {
|
||||
if (destroyed) return;
|
||||
try {
|
||||
const currentGeneration = ++generation;
|
||||
cleanups.forEach((cleanup) => cleanup());
|
||||
cleanups = [];
|
||||
@@ -145,18 +157,13 @@ export function mountBlockEditor(root: HTMLElement, options: MountEditorOptions)
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
try { destroy(); } finally { throw error; }
|
||||
}
|
||||
};
|
||||
refresh();
|
||||
return {
|
||||
refresh,
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
generation++;
|
||||
cleanups.forEach((cleanup) => cleanup());
|
||||
cleanups = [];
|
||||
manager?.destroy();
|
||||
live.remove();
|
||||
},
|
||||
destroy,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user