Repository navigation
devtools.cleanup() disconnects other stores sharing the same connection #3579
Unanswered
chungyo
asked this question in
Bug report
Replies: 2 comments 1 reply
|
Sounds valid. The patch looks a little bit complicated at a glance. I'll have a closer look later. |
1 reply
This comment was marked as duplicate.
This comment was marked as duplicate.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Bug Description
When two stores share a Redux DevTools connection (the same
name, with differentstoreidentifiers), callingdevtools.cleanup()on one store disconnects the other store's DevTools subscription as well.For example, create stores
firstandsecondwithname: 'shared', then callfirst.devtools.cleanup(). A subsequentJUMP_TO_STATEmessage no longer updatessecond, even though that store is still in use. Separate connections are unaffected.Expected: unsubscribe the cleaned-up store's listener, keep the shared connection working for the remaining stores, and close it when the last store is cleaned up.
Cause: the cleanup method calls
connection.unsubscribe(), which removes all listeners on the connection. Meanwhile, the per-listener unsubscribe callback returned byconnection.subscribe()is discarded. The two unsubscribe behaviors can be seen in the Redux DevTools implementation.Investigated against Zustand main at
b57db4f86ef179285da216eeb291266da82c361c. Related context: the cleanup API was introduced in #3111. This report concerns a surviving store on a shared connection.Reproduction Link
Regression tests and extension test double — see the
cleanupdescribe block. The test double models both per-listener unsubscribe and connection-wide unsubscribe.To reproduce in a fresh clone:
The fixed version passes all 67 DevTools tests. With the original middleware, the three new regression cases fail: the remaining store does not receive the state update, and the shared connection is closed prematurely. These results were verified with a mocked extension connection; a live browser extension has not been tested.
Prepared Fix
Commit and diff
The patch retains and invokes the per-store unsubscribe callback, closes the shared connection only after its last store is removed, and makes repeated cleanup calls harmless. It includes regression coverage for surviving stores, repeated cleanup, and connection recreation.
Validation on the fixed version: all 227 tests pass, along with type checking, lint, formatting, and the package build. Implementation and verification were AI-assisted.
GitHub currently limits PR creation here to collaborators, so this is being shared through Discussions. Would a maintainer be willing to open a PR from this branch or apply the patch? If applying it directly, please retain the original commit authorship. Feedback on the proposed behavior is welcome.
All reactions