Skip to content

feat: add devtools.cleanup() method#3111

Merged
dai-shi merged 7 commits intopmndrs:mainfrom
maxam2017:feat/devtools-cleanup
May 21, 2025
Merged

feat: add devtools.cleanup() method#3111
dai-shi merged 7 commits intopmndrs:mainfrom
maxam2017:feat/devtools-cleanup

Conversation

@maxam2017
Copy link
Copy Markdown
Contributor

Summary

When a store is wrapped in a context provider, remounting can cause duplicate instances in Redux DevTools; this patch adds a devtools.cleanup() method, allowing users to manually unsubscribe and clean up tracked connections.

Check List

  • pnpm run fix for formatting and linting code and docs

Note

related to #2254

@vercel
Copy link
Copy Markdown

vercel bot commented May 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zustand-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 0:47am

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented May 6, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented May 6, 2025

demostarter

npm i https://pkg.pr.new/zustand@3111

commit: d48fb3d

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented May 6, 2025

This sounds reasonable to me. Can anyone give a deep review?

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented May 17, 2025

@dbritto-dev What do you think?

@dbritto-dev
Copy link
Copy Markdown
Collaborator

@dai-shi LGTM but up to you

Copy link
Copy Markdown
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a closer look, but it looks good.
One concern, which is not this PR's fault, is that the code around connection info isn't very readable. It took me while to get it.

We would like to refactor in the future, and for that, can you add a test that depends on removeStoreFromTrackedConnections?

@dai-shi dai-shi added this to the v5.0.5 milestone May 17, 2025
@maxam2017
Copy link
Copy Markdown
Contributor Author

I had a closer look, but it looks good. One concern, which is not this PR's fault, is that the code around connection info isn't very readable. It took me while to get it.

We would like to refactor in the future, and for that, can you add a test that depends on removeStoreFromTrackedConnections?

@dai-shi
I'd like to test removeStoreFromTrackedConnections by verifying that the store is actually removed from the trackedConnections Map. However, since trackedConnections is a private variable within the module, I'm not sure how to properly test this.

Do you have any suggestions for how to test this functionality properly?
Thanks for your guidance!

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented May 20, 2025

Actually, I don't.
What would happen is memory leaks, but testing memory leaks isn't very straightforward.
Testing internal variables isn't nice either. (It's only testing implementation details.)

Actually, I have an idea. If we fail to remove from tracked connections,
after cleanup, when we try another connection, it will fail to connect again.
So, we should be able to test it from outside. Somewhat different, but kind of.

@maxam2017
Copy link
Copy Markdown
Contributor Author

Actually, I don't. What would happen is memory leaks, but testing memory leaks isn't very straightforward. Testing internal variables isn't nice either. (It's only testing implementation details.)

Actually, I have an idea. If we fail to remove from tracked connections, after cleanup, when we try another connection, it will fail to connect again. So, we should be able to test it from outside. Somewhat different, but kind of.

Here's the updated patch: 383d932. Let me know if anything needs to be adjusted!

Copy link
Copy Markdown
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for your contribution!

@dbritto-dev
Copy link
Copy Markdown
Collaborator

@dai-shi I'll take care of docs

@dbritto-dev dbritto-dev added the enhancement New feature or request label May 21, 2025
@dai-shi dai-shi merged commit b4177b3 into pmndrs:main May 21, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants