Repository navigation
extension: ignore repeated calls to a subscribe unsubscriber - #2138
Open
unknownhackerworld wants to merge 2 commits into
Open
unknownhackerworld wants to merge 2 commits into
unknownhackerworld wants to merge 2 commits into
Conversation
The function returned by connect().subscribe() looked up its listener with indexOf and passed the result straight to splice. After the first call the listener is gone, so indexOf returns -1 and splice(-1, 1) removes the last listener in the array instead: another subscriber's listener, or the internal listener that handles pause messages from the monitor (autoPause START/STOP and PAUSE_RECORDING). Only splice when the listener is found. Signed-off-by: Allen Joseph G <63872540+unknownhackerworld@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 15f24a4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Fixes #2137
Summary
The function returned by
connect().subscribe()inextension/src/pageScript/api/index.tsremoved its listener withlistenersForId.splice(listenersForId.indexOf(liftedListener), 1). On a second call the listener is already gone,indexOfreturns-1, andsplice(-1, 1)removes the last entry oflisteners[id]instead. That entry is either another subscriber's listener, or the internalrootListenerthatconnect()registers first, which handlesPAUSE_RECORDING(andSTART/STOPwithautoPause). After that, the other subscriber stops getting monitor messages, or pausing from the monitor stops reaching the page.Changes
splicewhen the listener is found (index !== -1), so calling an unsubscribe again is a no-op. This matches how Redux's ownstore.subscribeunsubscribe behaves.extension/test/app/inject/subscribe.spec.tswith two tests:PAUSE_RECORDINGdispatch must still produce theLIFTEDreply fromrootListener.Each test uses its own
instanceIdand targets messages withid, so the two connections do not interfere.remotedev-redux-devtools-extension.Alternatives considered
isSubscribedflag (the way Redux does it) would also work, but theindexOfcheck already gives the same result here without extra state.listeners[id] = listeners[id].filter(...)) would replace the array that thesubscribeclosure holds on to, so later subscribers and unsubscribes could act on a stale array. Keeping the in-placespliceavoids that.Testing
pnpm vitest --run --project extension test/app/inject/subscribe.spec.ts: both tests fail onmain(expected "vi.fn()" to be called 1 times, but got 0 timesandexpected null to match object { type: 'LIFTED', ... }) and pass with the fix.pnpm vitest --run --project extension test/app/inject: 6 files, 24 tests pass.oxlintandoxfmt --checkare clean on the changed files.AI assistance: this bug was found and the fix was drafted with AI tooling in my workflow.