-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix useSyncExternalStore
relying on changed render values
#3655
Conversation
Size Change: +74 B (0%) Total Size: 43.8 kB
ℹ️ View Unchanged
|
let i = 0; | ||
const getSnapshot = sinon.spy(() => { | ||
return () => 'value: ' + i++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getSnapshot must return a cached value. If getSnapshot is called multiple times in a row, it must return the same exact value unless there was a store update in between.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
fixes #3654
It looks like Apollo and other libs can have their snapshot changed during render time, i.e. not part of the subscribe, this means that we need to check in a layout effect whether we are due to re-render, luckily this is similar how React does it as well 😅