From f4eb85e2909c55155fa5dfdce9de49963834aec5 Mon Sep 17 00:00:00 2001 From: breken-ai <312387581+breken-ai@users.noreply.github.com> Date: Fri, 25 Sep 2026 20:40:23 -0700 Subject: [PATCH] fix(core): keep window listeners on removeAll removeAllListeners() cleared the map filled by registerWindowListener(), so window-backed events (e.g. Motion accel) never fired again after a later addListener() on web. Only unregister the handles. Co-Authored-By: Claude Opus 5.5 (1M context) --- core/src/tests/web-plugin.spec.ts | 23 +++++++++++++++++++++++ core/src/web-plugin.ts | 1 - 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/src/tests/web-plugin.spec.ts b/core/src/tests/web-plugin.spec.ts index 1e6d4a7f8d..b4c3a00871 100644 --- a/core/src/tests/web-plugin.spec.ts +++ b/core/src/tests/web-plugin.spec.ts @@ -182,6 +182,29 @@ describe('Web Plugin', () => { expect(handlerFunction).not.toHaveBeenCalled(); }); + it('Should re-register window listeners after removeAllListeners', async () => { + plugin.registerFakeWindowListener(); + + const lf1 = jest.fn(); + await plugin.addListener('test', lf1); + await plugin.removeAllListeners(); + + const lf2 = jest.fn(); + const handle = await plugin.addListener('test', lf2); + + const windowListener = plugin.getWindowListeners()['test']; + expect(windowListener).not.toBe(undefined); + expect(windowListener.registered).toEqual(true); + + window.dispatchEvent(new CustomEvent('fake', { detail: { value: 'after removeAll' } })); + + expect(lf1).not.toHaveBeenCalled(); + expect(lf2.mock.calls.length).toEqual(1); + expect(lf2.mock.calls[0][0].detail.value).toEqual('after removeAll'); + + await handle.remove(); + }); + it('Should not remove a listener if it is not found', async () => { const lf1 = (event: any) => { console.log(event); diff --git a/core/src/web-plugin.ts b/core/src/web-plugin.ts index 5fb324ee5f..4e03a7852a 100644 --- a/core/src/web-plugin.ts +++ b/core/src/web-plugin.ts @@ -45,7 +45,6 @@ export class WebPlugin implements Plugin { for (const listener in this.windowListeners) { this.removeWindowListener(this.windowListeners[listener]); } - this.windowListeners = {}; } protected notifyListeners(eventName: string, data: any, retainUntilConsumed?: boolean): void {