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

fix useSyncExternalStore relying on changed render values #3655

Merged
merged 3 commits into from
Aug 9, 2022

Conversation

JoviDeCroock
Copy link
Member

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 😅

@github-actions
Copy link

github-actions bot commented Aug 8, 2022

Size Change: +74 B (0%)

Total Size: 43.8 kB

Filename Size Change
compat/dist/compat.js 3.69 kB +25 B (0%)
compat/dist/compat.module.js 3.67 kB +22 B (0%)
compat/dist/compat.umd.js 3.76 kB +27 B (0%)
ℹ️ View Unchanged
Filename Size Change
debug/dist/debug.js 3 kB 0 B
debug/dist/debug.module.js 3 kB 0 B
debug/dist/debug.umd.js 3.08 kB 0 B
devtools/dist/devtools.js 229 B 0 B
devtools/dist/devtools.module.js 238 B 0 B
devtools/dist/devtools.umd.js 305 B 0 B
dist/preact.js 4 kB 0 B
dist/preact.min.js 4.03 kB 0 B
dist/preact.module.js 4.02 kB 0 B
dist/preact.umd.js 4.06 kB 0 B
hooks/dist/hooks.js 1.38 kB 0 B
hooks/dist/hooks.module.js 1.41 kB 0 B
hooks/dist/hooks.umd.js 1.47 kB 0 B
jsx-runtime/dist/jsxRuntime.js 317 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 327 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 395 B 0 B
test-utils/dist/testUtils.js 444 B 0 B
test-utils/dist/testUtils.module.js 444 B 0 B
test-utils/dist/testUtils.umd.js 521 B 0 B

compressed-size-action

let i = 0;
const getSnapshot = sinon.spy(() => {
return () => 'value: ' + i++;
Copy link
Member Author

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 99.291% when pulling b1d3ac3 on fix-use-sync-external-store into d483611 on master.

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@marvinhagemeister marvinhagemeister merged commit 1032d2b into master Aug 9, 2022
@marvinhagemeister marvinhagemeister deleted the fix-use-sync-external-store branch August 9, 2022 06:51
@JoviDeCroock JoviDeCroock mentioned this pull request Aug 9, 2022
JoviDeCroock added a commit that referenced this pull request Sep 2, 2022
JoviDeCroock added a commit that referenced this pull request Sep 2, 2022
* backport #3615

* backport #3633

* backport #3643

* backport #3655

* backport #3663

* backport #3690

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

Successfully merging this pull request may close these issues.

@apollo/client + useSyncExternalStore - data updates not working since 10.9.0+
3 participants