Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): clean stream owner after navigation commits (r8-m5)
Josuéd7edeb692750
diff --git a/desktop-app/src/__tests__/ipc.entityChanges.test.ts b/desktop-app/src/__tests__/ipc.entityChanges.test.tsindex 9c1981c42..95a92a3f7 100644--- a/desktop-app/src/__tests__/ipc.entityChanges.test.ts+++ b/desktop-app/src/__tests__/ipc.entityChanges.test.ts@@ -39,7 +39,7 @@ beforeAll(async () => {})describe('entityChanges:streamStart renderer lifecycle', () => {- it('releases subscribers on main-frame reload and permits the new renderer to resubscribe', async () => {+ it('releases subscribers only after committed main-frame navigation', async () => {const sender = Object.assign(new EventEmitter(), { id: 71, send: vi.fn() })const event = { sender, senderFrame: { url: 'file:///app/index.html' } }@@ -49,7 +49,13 @@ describe('entityChanges:streamStart renderer lifecycle', () => {sender.emit('did-start-navigation', {}, 'file:///app/child', false, false)expect(service.stopEntityChangeStreamsForOwner).not.toHaveBeenCalled()- sender.emit('did-start-navigation', {}, 'file:///app/index.html', false, true)+ // A navigation may be prevented after it starts; an in-place navigation+ // also retains the current document and its stream owner.+ sender.emit('did-start-navigation', {}, 'file:///app/blocked', false, true)+ sender.emit('did-start-navigation', {}, 'file:///app/index.html#tab', true, true)+ expect(service.stopEntityChangeStreamsForOwner).not.toHaveBeenCalled()++ sender.emit('did-navigate', {}, 'file:///app/index.html', 200, 'OK')expect(service.stopEntityChangeStreamsForOwner).toHaveBeenCalledTimes(1)expect(service.stopEntityChangeStreamsForOwner).toHaveBeenCalledWith(71)diff --git a/desktop-app/src/ipc.ts b/desktop-app/src/ipc.tsindex 9d935c6bf..4b9fc50aa 100644--- a/desktop-app/src/ipc.ts+++ b/desktop-app/src/ipc.ts@@ -897,20 +897,23 @@ export function registerIpcHandlers(service: AppService): void {cleanedUp = trueservice.stopEntityChangeStreamsForOwner(ownerId)entityChangeOwnerCleanupRegistered.delete(ownerId)- event.sender.removeListener('did-start-navigation', onMainFrameNavigation)+ event.sender.removeListener('did-navigate', onMainFrameNavigation)event.sender.removeListener('render-process-gone', onRendererProcessGone)event.sender.removeListener('destroyed', cleanup)}const onMainFrameNavigation = (_navigationEvent: Electron.Event,_navigationUrl: string,- _isInPlace: boolean,- isMainFrame: boolean+ _httpResponseCode: number,+ _httpStatusText: string) => {- if (isMainFrame) cleanup()+ cleanup()}const onRendererProcessGone = (_event: Electron.Event) => cleanup()- event.sender.on('did-start-navigation', onMainFrameNavigation)+ // `did-navigate` is emitted after a committed main-frame navigation.+ // `did-start-navigation` also fires for cancelled and in-place changes,+ // which do not replace this renderer's stream owner.+ event.sender.on('did-navigate', onMainFrameNavigation)event.sender.on('render-process-gone', onRendererProcessGone)event.sender.once('destroyed', cleanup)}