fix(webview): stop URL bar revert and pubsub handler leak (#1482)#1493
Open
thingnoy wants to merge 1 commit intoresponsively-org:mainfrom
Open
fix(webview): stop URL bar revert and pubsub handler leak (#1482)#1493thingnoy wants to merge 1 commit intoresponsively-org:mainfrom
thingnoy wants to merge 1 commit intoresponsively-org:mainfrom
Conversation
…ly-org#1482) Two related issues in desktop-app/src/renderer/components/Previewer/Device/index.tsx: 1. Address-bar URL revert / "navigation does nothing" (issue responsively-org#1482) <webview src={address}> bound to Redux address competed with ref.current.loadURL(address) in the [address] effect. After the Electron 40 upgrade (responsively-org#1473) this race left the webview wedged on the previously loaded URL — typing a new URL and pressing Enter updated Redux but did not actually navigate. Secondary devices were even worse, since the loadURL effect was guarded by isPrimary and they relied solely on src reactivity. Fix: capture the address once on mount as initialAddress and pass that to <webview src>, then route every navigation through loadURL. Removed the isPrimary guard from the loadURL effect so secondary devices stay in sync; the isNavigatingFromAddressBar flag remains primary-only because only the primary device's webview drives address-bar state. 2. PubSub subscriber leak on Back / Forward / Reload / Delete * registerNavigationHandlers subscribed to RELOAD/BACK/FORWARD and the DELETE_STORAGE/COOKIES/CACHE topics, but it ran from a useEffect whose deps included address. Every navigation re-ran the effect and added another subscriber without removing the previous one. After N navigations a single Back click replayed the handler N times, jumping multiple history entries. Fix: registerNavigationHandlers now returns an unsubscribe fn that removes every handler it subscribed; the big effect stores it and invokes it from cleanup alongside the existing webview-event removers. yarn typecheck passes.
|
|
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
Fixes: #1482
ℹ️ About the PR
Two related fixes for
desktop-app/src/renderer/components/Previewer/Device/index.tsx. They are independent in scope but small enough to review together.🐛 Bug 1 — Address bar URL revert (the user-visible #1482 symptom)
The webview is bound twice to the Redux
address:<webview src={address} ... />— React updates thesrcattribute whenever Redux changes.useEffect:ref.current.loadURL(address)— also callsloadURLwhenever Redux changes.After Electron 40 (#1473), these two paths race for primary devices, and for non-primary devices the
useEffectwas guarded byisPrimary, leaving secondary previews navigating only viasrcreactivity. The end result on Linux/Windows builds was the webview getting wedged on the first URL — typing a new URL in the address bar dispatchessetAddress, but<webview>does not actually navigate.Fix: Drop reactive
srcupdates and route every navigation throughloadURL:initialAddressand pass that to<webview src>.isPrimaryguard from theloadURLeffect so secondary devices stay in sync too. TheisNavigatingFromAddressBarflag remains primary-only because only the primary device's webview drives address-bar state.This matches the approach in #1486; this PR is a clean version that does not also delete
release/app/{package.json,package-lock.json,yarn.lock}.🐛 Bug 2 — PubSub subscriber leak on Back/Forward/Reload/Delete Cache/Cookies/Storage
registerNavigationHandlerscallswebViewPubSub.subscribe(...)forRELOAD,BACK,FORWARD,DELETE_STORAGE,DELETE_COOKIES,DELETE_CACHE. It is invoked from auseEffectwhose dependency list includesaddress, so it runs on every navigation. There is no matchingunsubscribein the cleanup, so subscribers accumulate without bound.After N navigations, a single Back/Forward/Reload click fires N copies of the handler.
goBack()/goForward()then jump multiple history entries (or queue rapidly), and Delete Cookies/Cache/Storage make redundant IPC calls.Fix: Have
registerNavigationHandlersreturn an unsubscribe function that removes every handler it subscribed. The big effect now stores that fn and invokes it from cleanup alongside the existing webview-event removers.🎯 Result
srcupdates.🖼️ Testing
yarn typecheckpasses.🔍 Files changed
desktop-app/src/renderer/components/Previewer/Device/index.tsxonly.