Repository navigation
fix: reject pending requests when the popup is closed without PopupUnload - #1942
Draft
wcrozier12 wants to merge 1 commit into
Draft
wcrozier12 wants to merge 1 commit into
wcrozier12 wants to merge 1 commit into
Conversation
…load A popup closed before the wallet page loads never posts PopupLoadedV2 or PopupUnload, so the handshake and any pending request waited forever and their listeners stayed attached. A later popup's PopupLoadedV2 could then resolve the stale waiter. Poll popup.closed while the communicator holds a popup and run the existing disconnect path when it reports closed, so pending requests reject with the same user-rejected error as an unload. The poll is cleared on disconnect.
Collaborator
🟡 Heimdall Review Status
|
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.
Title: fix: reject pending requests when the popup is closed without PopupUnload
Summary
If the user closes the wallet popup before the wallet page loads, the page never posts
PopupLoadedV2orPopupUnload. TheCommunicatoronly learns that a popup went away fromPopupUnload, so in that case the handshake and any pending request wait forever, and theirmessagelisteners stay attached.There is a second effect.
onMessagefilters by origin only, and the next request opens a new popup because the old one reportsclosed. That new window'sPopupLoadedV2also resolves the stale waiter from the closed popup.This change makes the
Communicatorpollpopup.closedevery 500 ms while it holds a popup. When the popup reports closed, it runs the existingdisconnect()path, so every pending request rejects with the sameuserRejectedRequest('Request rejected')error users get today when the wallet postsPopupUnload.openPopupreturns a window. That covers windows from a customopenFnand from the popup-blocked dialog's retry.disconnect()clears the poll, so it stops onPopupUnload, on a detected close, and is replaced if a new popup is opened.closedis wrapped in a try/catch. If it throws, the poll skips that tick and checks again on the next one.PopupUnloadarrives as it does today.Not in this PR: checking
event.sourceon incoming messages, and a public way to cancel a pending request. Those could be follow-ups.How did you test your changes?
Added unit tests in
Communicator.test.tsthat use fake timers:PopupUnload: the request rejects with the user-rejected error.PopupUnloadarrives as usual: one disconnect, the poll is cleared, and a latercloseddoes not disconnect a second time.Without the fix, the three closed-popup tests fail (two time out, one posts into the new popup).
Commands:
yarn build(packages/wallet-sdk): passesyarn test --run(packages/wallet-sdk): 526 tests passyarn typecheck,yarn lint,yarn format:check: pass