@samitouri / QOS-React-1 / commits / c5eca9b082

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 https://github.com/facebook/react/issues/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. -->

Jelle Voost committed Jul 13, 2024 at 05:57 UTC c5eca9b0824b6325dbc9613f9befb41077fe35a0
1 file changed +3
packages/use-sync-external-store/src/useSyncExternalStoreWithSelector.js
+3
@@ -93,6 +93,9 @@ export function useSyncExternalStoreWithSelector<Snapshot, Selection>(
93 // to React that the selections are conceptually equal, and we can bail
94 // out of rendering.
95 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;
99 return prevSelection;
100 }
101