Repository navigation
fix(desktop-app): make ipcRenderer.removeListener remove what on registered - #1561
Open
nazarli-shabnam wants to merge 1 commit into
Open
nazarli-shabnam wants to merge 1 commit into
nazarli-shabnam wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ 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.useDeviceNavigationis one such caller (AboutDialogandSitePermissionsuse 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'
reloadhandlers are still subscribed and callreload()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
removeListenerandremoveAllListenersremove the wrapper they stand for. The function returned byon()also drops its registration. No call sites change.🖼️ Testing Scenarios / Screenshots
src/main/preload.test.ts(6 cases) importing the preload with a mockedelectron: handler receives args without the event,removeListenerremoves only the given handler on the given channel, the returned unsubscribe works,removeAllListenersclears the channel. The tworemoveListenercases fail without the change.tsc --noEmitandeslint --max-warnings 0pass on the changed files.vitest run: 279 pass; 2 darwin-only tests insrc/mcp-cli/launch.test.tsfail on my Windows machine, in code this PR does not touch.