fix(plugins): skip modal teardown for stale plugin panel closes

handleModalClosed now reports whether teardown should continue. A late
close notice for a replaced panel returns before the generic modal-close
flow, so it no longer hides the modal window showing the newer panel.
This commit is contained in:
sudacode committed 2026-10-26 22:57:45 -07:00
1 parent d5fb43caa3
commit 04c91add22
3 files changed
+26 -9

No files matched your search

+8 -3
View File
@@ -6040,12 +6040,17 @@ const { registerIpcRuntimeHandlers } = composeIpcRuntimeHandlers({
}
},
onOverlayModalClosed: (modal, senderWindow, instanceId) => {
// A late close for a replaced plugin panel must not hide the panel now showing.
if (
modal === 'plugin-panel' &&
instanceId !== undefined &&
!pluginPanelRuntime.handleModalClosed(instanceId)
) {
return;
}
if (modal === 'media-timing-review') {
void mediaTimingReviewRuntime.dispose();
}
if (modal === 'plugin-panel' && instanceId !== undefined) {
pluginPanelRuntime.handleModalClosed(instanceId);
}
if (modal === 'subtitle-sidebar' && senderWindow === overlayManager.getMainWindow()) {
subtitleSidebarRequestedOpen = false;
}
@@ -44,7 +44,7 @@ test('closing from the overlay aborts the handle and ignores later updates', asy
await new Promise((resolve) => setImmediate(resolve));
const sentBefore = h.sent.length;
h.runtime.handleModalClosed(1);
assert.equal(h.runtime.handleModalClosed(1), true);
panel.update({ markdown: 'too late' });
assert.equal(panel.signal.aborted, true);
@@ -58,11 +58,17 @@ test('a late close acknowledgement for a replaced panel leaves the new panel ope
first.close();
const second = h.runtime.open({ title: 'Two', markdown: '' });
h.runtime.handleModalClosed(1);
assert.equal(h.runtime.handleModalClosed(1), false, 'skip teardown of the newer panel');
assert.equal(second.signal.aborted, false);
});
test('a close notice after the plugin closed its panel still tears the modal down', () => {
const h = createHarness(Promise.resolve(true));
h.runtime.open({ title: 'One', markdown: '' }).close();
assert.equal(h.runtime.handleModalClosed(1), true);
});
test('opening a new panel aborts the previous one', () => {
const h = createHarness(Promise.resolve(true));
const first = h.runtime.open({ title: 'One', markdown: '' });
+9 -3
View File
@@ -103,9 +103,15 @@ export function createPluginPanelRuntime(deps: {
};
},
/** The overlay closed `panelId`; a late notice for an already replaced panel is ignored. */
handleModalClosed(panelId: number): void {
if (active?.panelId === panelId) finish(active);
/**
* The overlay closed `panelId`. Returns false for a late notice about a panel that a newer one
* already replaced, so the caller skips the modal teardown that would hide the newer panel.
*/
handleModalClosed(panelId: number): boolean {
if (!active) return true;
if (active.panelId !== panelId) return false;
finish(active);
return true;
},
};
}