diff --git a/frontend/scripts/test-plugins.mjs b/frontend/scripts/test-plugins.mjs index 36e4cbb..ba534f7 100644 --- a/frontend/scripts/test-plugins.mjs +++ b/frontend/scripts/test-plugins.mjs @@ -330,10 +330,12 @@ test('closing a page retries cleanup of a late task after rate limiting', async assert.equal(attempts, 2) }) -test('pruning removes a view and dialogs when their conditions stop matching', () => { +test('pruning removes an unavailable page but keeps open dialogs until their VM disappears', () => { const page = { pluginId: 'demo', viewId: 'vm', location: 'vm.tab', vm: 'vm-1' } const dialog = { ...page, viewId: 'dialog', location: 'dialog' } let state = openPluginView(emptyPluginViewState, page) state = openPluginView(state, dialog) - assert.deepEqual(prunePluginViews(state, new Set(['demo/vm', 'demo/dialog']), () => true, () => false), emptyPluginViewState) + const views = new Set(['demo/vm', 'demo/dialog']) + assert.deepEqual(prunePluginViews(state, views, () => true, () => false), { ...emptyPluginViewState, dialogs: [dialog] }) + assert.deepEqual(prunePluginViews(state, views, () => false), emptyPluginViewState) }) diff --git a/frontend/src/lib/pluginViewEvents.ts b/frontend/src/lib/pluginViewEvents.ts index 81791de..ddc63b2 100644 --- a/frontend/src/lib/pluginViewEvents.ts +++ b/frontend/src/lib/pluginViewEvents.ts @@ -4,7 +4,13 @@ export type PluginHostEventListener = (event: PluginHostEvent, data: unknown) => const listeners = new Set() export function publishPluginHostEvent(event: PluginHostEvent, data: unknown): void { - for (const listener of [...listeners]) listener(event, data) + for (const listener of [...listeners]) { + try { + listener(event, data) + } catch (error) { + console.warn('[plugin] could not deliver host event:', event, error) + } + } } export function subscribePluginHostEvents(listener: PluginHostEventListener): () => void { diff --git a/frontend/src/lib/pluginViewRouter.ts b/frontend/src/lib/pluginViewRouter.ts index f1ee9f1..b58e806 100644 --- a/frontend/src/lib/pluginViewRouter.ts +++ b/frontend/src/lib/pluginViewRouter.ts @@ -67,11 +67,12 @@ export function prunePluginViews( validVM: (vm: string | undefined) => boolean, available: (route: PluginViewRoute) => boolean = () => true, ): PluginViewState { - const valid = (route: PluginViewRoute) => validViews.has(pluginViewKey(route)) && (route.location !== 'vm.tab' || validVM(route.vm)) && available(route) - const route = state.route && valid(state.route) ? state.route : null + const valid = (route: PluginViewRoute) => validViews.has(pluginViewKey(route)) && (!route.vm || validVM(route.vm)) + const usable = (route: PluginViewRoute) => valid(route) && available(route) + const route = state.route && usable(state.route) ? state.route : null return { route, dialogs: state.dialogs.filter(valid), - returnStack: route ? state.returnStack.filter(valid) : [], + returnStack: route ? state.returnStack.filter(usable) : [], } }