Skip to content

Commit c5eca9b

Browse files
authored
Fixed useSyncExternalStoreWithSelector to update memoizedSnapshot on 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. -->
1 parent 127a0fb commit c5eca9b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export function useSyncExternalStoreWithSelector<Snapshot, Selection>(
9393
// to React that the selections are conceptually equal, and we can bail
9494
// out of rendering.
9595
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
96+
// The snapshot still has changed, so make sure to update to not keep
97+
// old references alive
98+
memoizedSnapshot = nextSnapshot;
9699
return prevSelection;
97100
}
98101

0 commit comments

Comments
 (0)