Skip to content

Commit

Permalink
Fixed useSyncExternalStoreWithSelector to update memoizedSnapshot o…
Browse files Browse the repository at this point in the history
…n change (#25968)

## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

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

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
  • Loading branch information
jellevoost authored Jul 13, 2024
1 parent 127a0fb commit c5eca9b
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export function useSyncExternalStoreWithSelector<Snapshot, Selection>(
// to React that the selections are conceptually equal, and we can bail
// out of rendering.
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
// The snapshot still has changed, so make sure to update to not keep
// old references alive
memoizedSnapshot = nextSnapshot;
return prevSelection;
}

Expand Down

0 comments on commit c5eca9b

Please sign in to comment.