Skip to content

fix(desktop-app): make ipcRenderer.removeListener remove what on registered - #1561

Open
nazarli-shabnam wants to merge 1 commit into
responsively-org:mainfrom
nazarli-shabnam:fix/1175-ipc-remove-listener
Open

nazarli-shabnam wants to merge 1 commit into
responsively-org:mainfrom
nazarli-shabnam:fix/1175-ipc-remove-listener

Conversation

@nazarli-shabnam

Copy link
Copy Markdown

✨ Pull Request

📓 Referenced Issue

Related to #1175 (I could not run the packaged app, so I am not claiming it closes the issue; see below).

ℹ️ About the PR

window.electron.ipcRenderer.on() registers a wrapper (it drops the IPC event argument), so the caller's own function is never the registered listener. removeListener(channel, handler) therefore matched nothing, and handlers of unmounted components stayed subscribed. useDeviceNavigation is one such caller (AboutDialog and SitePermissions use the same pairing).

This fits what people report on #1175: reload works at first, then stops after switching layout. After a layout switch the old devices' reload handlers are still subscribed and call reload() on detached webviews, which throws. EventEmitter stops at the first listener that throws, so the live devices never get the message.

The bridge now remembers each registration, so removeListener and removeAllListeners remove the wrapper they stand for. The function returned by on() also drops its registration. No call sites change.

🖼️ Testing Scenarios / Screenshots

  • Added src/main/preload.test.ts (6 cases) importing the preload with a mocked electron: handler receives args without the event, removeListener removes only the given handler on the given channel, the returned unsubscribe works, removeAllListeners clears the channel. The two removeListener cases fail without the change.
  • tsc --noEmit and eslint --max-warnings 0 pass on the changed files.
  • Full vitest run: 279 pass; 2 darwin-only tests in src/mcp-cli/launch.test.ts fail on my Windows machine, in code this PR does not touch.
  • Not tested: the Ctrl/Cmd+R behavior in a running Electron app.

…stered

The preload bridge registered a wrapper around the handler passed to on(),
so removeListener(channel, handler) never matched a registered listener.
Handlers of unmounted components stayed subscribed: after switching layouts
the stale reload handlers called reload() on detached webviews and threw,
and since EventEmitter stops at the first throwing listener the live
devices never received the reload.

Track each registration so removeListener and removeAllListeners remove the
wrapper they stand for.

Related to responsively-org#1175

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant