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

useSyncExternalStore refinements #9709

Merged
merged 4 commits into from
May 12, 2022
Merged

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented May 11, 2022

I was able to reproduce @SimenB's webpack bug report from #9675 (comment), and I am confident this PR will fix that problem.

I also restructured the code so that when the real React.useSyncExternalStore is available, it will be the same (===) function we export as useSyncExternalStore, without any additional wrapping.

Comment on lines -18 to -29
export const useSyncExternalStore: RealUseSESHookType = (
// When/if React.useSyncExternalStore is defined, delegate fully to it.
export const useSyncExternalStore: RealUseSESHookType = realHook || ((
subscribe,
getSnapshot,
getServerSnapshot,
) => {
// When/if React.useSyncExternalStore is defined, delegate fully to it.
const realHook = (React as {
useSyncExternalStore?: RealUseSESHookType;
}).useSyncExternalStore;
if (realHook) {
return realHook(subscribe, getSnapshot, getServerSnapshot);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I think you'll appreciate this change @brainkim

@brainkim
Copy link
Contributor

Thank you for doing this!

@benjamn benjamn merged commit 06cf0b8 into main May 12, 2022
benjamn added a commit that referenced this pull request May 12, 2022
@benjamn benjamn deleted the useSyncExternalStore-refinements branch May 13, 2022 20:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants