Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed useSyncExternalStoreWithSelector to update memoizedSnapshot on change #25968

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jellevoost
Copy link

@jellevoost jellevoost commented Jan 6, 2023

Summary

A proposed fix for the bug described in #25967

How did you test this change?

See the issue linked above, test scenario included in the code sandbox: https://codesandbox.io/s/fervent-ives-0vm9es?file=/src/App.jsx

@jellevoost jellevoost changed the title Fixed useSyncExternalStoreWithSelector to update memoizedSnapshot … Fixed useSyncExternalStoreWithSelector to update memoizedSnapshot on change Jan 6, 2023
@jellevoost
Copy link
Author

Unfortunately I did not figure out a way to properly unit test this issue which is why I've included the sandbox to prove that the fix works as intended. If anyone has any idea on how to add a unit test to this I would be happy to add them!

@softstrong
Copy link

oh nice

@jkillian
Copy link

jkillian commented Dec 4, 2023

Hi @jellevoost - I'm finding the stale snapshot issue this fixes is a serious issue for our application. Did you end up using this solution in your own code, and if so, did it work well for you? I'm likely going to pick it up for our codebase but just wanted to do a bit of due diligence first in case you had any other findings since this PR was created. Thanks for figuring this out!

@jellevoost
Copy link
Author

Hi @jellevoost - I'm finding the stale snapshot issue this fixes is a serious issue for our application. Did you end up using this solution in your own code, and if so, did it work well for you? I'm likely going to pick it up for our codebase but just wanted to do a bit of due diligence first in case you had any other findings since this PR was created. Thanks for figuring this out!

As it was quite a serious problem for me as well (leading to quite a few OOM crashes) I did include the fix and it has no longer posed any problem or any noticeable side-effect since (and there are quite a bunch of users that use it extensively). Since in my case the problem was only present in combination of react-redux (as it was using the use-sync-external-store shim) the fix was included the react-redux and patched in there. I've not yet tested v9 of react-redux in combination with react 18.2.0, but looking at the changes I think the problem still exists there (but you can no longer fix the shim included in react-redux as it relies fully on react 18 now) and you would have to patch react with this change.

Copy link

github-actions bot commented Apr 9, 2024

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 9, 2024
@markerikson
Copy link
Contributor

Not stale

@jkillian
Copy link

jkillian commented Apr 9, 2024

Will mention for anyone else stumbling here that we've been applying @jellevoost's change to use-sync-external-store using patch-package and it's been working well to resolve the memory issues we saw without any noticeable negative effects!

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
@jy14898
Copy link

jy14898 commented Apr 13, 2024

Unfortunately I did not figure out a way to properly unit test this issue which is why I've included the sandbox to prove that the fix works as intended. If anyone has any idea on how to add a unit test to this I would be happy to add them!

Looks like there's a PR implementing the same fix but with a test #27776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants