GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement useSyncExternalStore on server by acdlite · Pull Request #22347 · react/react

Conversation

@acdlite

@acdlite acdlite commented Sep 17, 2021

Copy link
Copy Markdown
Collaborator

Adds a third argument called getServerSnapshot.

On the server, React calls this one instead of the normal getSnapshot. We also call it during hydration.

So it represents the snapshot that is used to generate the initial, server-rendered HTML. The purpose is to avoid server-client mismatches. What we render during hydration needs to match up exactly with what we render on the server.

The pattern is for the server to send down a serialized copy of the store that was used to generate the initial HTML. On the client, React will call either getSnapshot or getServerSnapshot on the client as appropriate, depending on whether it's currently hydrating.

The argument is optional for fully client rendered use cases. If the user does attempt to omit getServerSnapshot, and the hook is called on the server, React will abort that subtree on the server and revert to client rendering, up to the nearest Suspense boundary.

For the userspace shim, we will need to use a heuristic (canUseDOM) to determine whether we are in a server environment. I'll do that in a follow up.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brainkim reacted with eyes emoji
All reactions
  • 👀 1 reaction
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 17, 2021
@sizebot

sizebot commented Sep 17, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Comparing: 57e4d68...ffdf8a1

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js +0.04% 127.38 kB 127.43 kB +0.06% 40.58 kB 40.61 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.04% 130.20 kB 130.26 kB +0.07% 41.50 kB 41.53 kB
facebook-www/ReactDOM-prod.classic.js +0.07% 405.21 kB 405.48 kB +0.11% 74.99 kB 75.07 kB
facebook-www/ReactDOM-prod.modern.js +0.07% 393.80 kB 394.07 kB +0.11% 73.28 kB 73.36 kB
facebook-www/ReactDOMForked-prod.classic.js +0.07% 405.21 kB 405.48 kB +0.11% 74.99 kB 75.07 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store-extra.development.js +26.28% 4.02 kB 5.08 kB +10.12% 1.54 kB 1.70 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-extra.development.js +26.28% 4.02 kB 5.08 kB +10.12% 1.54 kB 1.70 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store-extra.development.js +26.28% 4.02 kB 5.08 kB +10.12% 1.54 kB 1.70 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store-extra.production.min.js +9.72% 0.97 kB 1.06 kB +8.27% 0.56 kB 0.60 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-extra.production.min.js +9.72% 0.97 kB 1.06 kB +8.27% 0.56 kB 0.60 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store-extra.production.min.js +9.72% 0.97 kB 1.06 kB +8.27% 0.56 kB 0.60 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/use-sync-external-store/cjs/use-sync-external-store-extra.development.js +26.28% 4.02 kB 5.08 kB +10.12% 1.54 kB 1.70 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-extra.development.js +26.28% 4.02 kB 5.08 kB +10.12% 1.54 kB 1.70 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store-extra.development.js +26.28% 4.02 kB 5.08 kB +10.12% 1.54 kB 1.70 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store-extra.production.min.js +9.72% 0.97 kB 1.06 kB +8.27% 0.56 kB 0.60 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store-extra.production.min.js +9.72% 0.97 kB 1.06 kB +8.27% 0.56 kB 0.60 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store-extra.production.min.js +9.72% 0.97 kB 1.06 kB +8.27% 0.56 kB 0.60 kB
oss-experimental/use-sync-external-store/cjs/use-sync-external-store.development.js +1.43% 7.12 kB 7.23 kB +1.61% 2.92 kB 2.97 kB
oss-stable-semver/use-sync-external-store/cjs/use-sync-external-store.development.js +1.43% 7.12 kB 7.23 kB +1.61% 2.92 kB 2.97 kB
oss-stable/use-sync-external-store/cjs/use-sync-external-store.development.js +1.43% 7.12 kB 7.23 kB +1.61% 2.92 kB 2.97 kB
facebook-www/ReactDOMServer-prod.classic.js +0.26% 47.59 kB 47.71 kB +0.25% 11.17 kB 11.19 kB
facebook-react-native/react/cjs/React-prod.js +0.25% 16.60 kB 16.64 kB +0.23% 4.26 kB 4.27 kB
facebook-react-native/react/cjs/React-profiling.js +0.25% 16.60 kB 16.64 kB +0.23% 4.26 kB 4.27 kB
facebook-www/React-prod.modern.js +0.25% 16.73 kB 16.77 kB +0.23% 4.30 kB 4.31 kB
facebook-www/React-profiling.modern.js +0.25% 16.73 kB 16.77 kB +0.23% 4.30 kB 4.31 kB
facebook-www/React-prod.classic.js +0.25% 16.87 kB 16.92 kB +0.28% 4.34 kB 4.36 kB
facebook-www/React-profiling.classic.js +0.25% 16.87 kB 16.92 kB +0.28% 4.34 kB 4.36 kB

Generated by 🚫 dangerJS against ffdf8a1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@acdlite
acdlite force-pushed the getserversnapshot branch 2 times, most recently from bb9fcad to 3577be8 Compare September 17, 2021 17:29
@acdlite
acdlite requested review from rickhanlonii, salazarm and sebmarkbage September 17, 2021 17:35
@acdlite
acdlite marked this pull request as ready for review September 17, 2021 17:51
salazarm
salazarm reviewed Sep 17, 2021
View reviewed changes
Comment thread packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js Outdated

@salazarm salazarm Sep 17, 2021

Copy link
Copy Markdown
Contributor

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.

noob q: I see we use this everywhere in tests, why is it needed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@salazarm salazarm Sep 17, 2021

Copy link
Copy Markdown
Contributor

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.

Oh is it just as a way to avoid relying on implementation details for testing if a codepath executed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@acdlite acdlite Sep 17, 2021

Copy link
Copy Markdown
Collaborator Author

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.

It's a common testing pattern we use. yieldValue pushes something into a log, and then we later assert the output of that log.

The reason it's a Scheduler API is that we also use it to perform some partial work and then yield right after, to test concurrent tasks:

scheduleSomeWork(); // e.g. a React update
expect(Scheduler).toFlushAndYieldThrough([
  'child 1',
  'child 2,'
]);

// The work is paused. Do something concurrent, like an interleaved input event.

// Then flush the rest of the work
expect(Scheduler).toFlushAndYield([
  'child 3',
  'child 4,'
]);

// Assert on final result

It's probably not the most intuitive name; it's inspired by the yield keyword for generator functions since that's roughly the way it's used.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

salazarm and rickhanlonii reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@acdlite acdlite mentioned this pull request Sep 17, 2021
Initial experimental React 18 compat prototyping reduxjs/react-redux#1808
Merged
This was referenced Sep 18, 2021
Build use-sync-external-store in codesandbox-ci #22352
Closed
React 18: hydration mismatch when an external store is updated in an effect #22361
Closed
salazarm
salazarm approved these changes Sep 20, 2021
View reviewed changes
@acdlite
Implement useSyncExternalStore on server
ffdf8a1
Adds a third argument called `getServerSnapshot`.

On the server, React calls this one instead of the normal `getSnapshot`.
We also call it during hydration.

So it represents the snapshot that is used to generate the initial,
server-rendered HTML. The purpose is to avoid server-client mismatches.
What we render during hydration needs to match up exactly with what we
render on the server.

The pattern is for the server to send down a serialized copy of the
store that was used to generate the initial HTML. On the client, React
will call either `getSnapshot` or `getServerSnapshot` on the client as
appropriate, depending on whether it's currently hydrating.

The argument is optional for fully client rendered use cases. If the
user does attempt to omit `getServerSnapshot`, and the hook is called
on the server, React will abort that subtree on the server and
revert to client rendering, up to the nearest Suspense boundary.

For the userspace shim, we will need to use a heuristic (canUseDOM)
to determine whether we are in a server environment. I'll do that in
a follow up.
@acdlite
acdlite force-pushed the getserversnapshot branch from 3577be8 to ffdf8a1 Compare September 20, 2021 15:23
@acdlite
acdlite merged commit 86b3e24 into react:main Sep 20, 2021
facebook-github-bot pushed a commit to react/react-native that referenced this pull request Oct 12, 2021
Andrei Shikov @facebook-github-bot
React Native sync for revisions e8feb11...afcb9cd
c75ad2c
Summary:
This sync includes the following changes:
- **[579c008](react/react@579c008a7 )**: [Fizz/Flight] pipeToNodeWritable(..., writable).startWriting() -> renderToPipeableStream(...).pipe(writable) ([#22450](react/react#22450)) //<Sebastian Markbåge>//
- **[f2c3811](react/react@f2c381131 )**: fix: useSyncExternalStoreExtra ([#22500](react/react#22500)) //<Daishi Kato>//
- **[0ecbbe1](react/react@0ecbbe142 )**: Sync hydrate discrete events in capture phase and dont replay discrete events ([#22448](react/react#22448)) //<salazarm>//
- **[a724a3b](react/react@a724a3b57 )**: [RFC] Codemod invariant -> throw new Error ([#22435](react/react#22435)) //<Andrew Clark>//
- **[201af81](react/react@201af81b0 )**: Release pooled cache reference in complete/unwind ([#22464](react/react#22464)) //<Joseph Savona>//
- **[033efe7](react/react@033efe731 )**: Call get snapshot in useSyncExternalStore server shim ([#22453](react/react#22453)) //<salazarm>//
- **[7843b14](react/react@7843b142a )**: [Fizz/Flight] Pass in Destination lazily to startFlowing instead of in createRequest ([#22449](react/react#22449)) //<Sebastian Markbåge>//
- **[d9fb383](react/react@d9fb383d6 )**: Extract queueing logic into shared functions ([#22452](react/react#22452)) //<Andrew Clark>//
- **[9175f4d](react/react@9175f4d15 )**: Scheduling Profiler: Show Suspense resource .displayName ([#22451](react/react#22451)) //<Brian Vaughn>//
- **[eba248c](react/react@eba248c39 )**: [Fizz/Flight] Remove reentrancy hack ([#22446](react/react#22446)) //<Sebastian Markbåge>//
- **[6638815](react/react@66388150e )**: Remove usereducer eager bailout ([#22445](react/react#22445)) //<Joseph Savona>//
- **[d3e0869](react/react@d3e086932 )**: Make root.unmount() synchronous  ([#22444](react/react#22444)) //<Andrew Clark>//
- **[2cc6d79](react/react@2cc6d79c9 )**: Rename onReadyToStream to onCompleteShell ([#22443](react/react#22443)) //<Sebastian Markbåge>//
- **[c88fb49](react/react@c88fb49d3 )**: Improve DEV errors if string coercion throws (Temporal.*, Symbol, etc.) ([#22064](react/react#22064)) //<Justin Grant>//
- **[05726d7](react/react@05726d72c )**: [Fix] Errors should not "unsuspend" a transition ([#22423](react/react#22423)) //<Andrew Clark>//
- **[3746eaf](react/react@3746eaf98 )**: Packages/React/src/ReactLazy ---> changing -1 to unintialized ([#22421](react/react#22421)) //<BIKI DAS>//
- **[04ccc01](react/react@04ccc01d9 )**: Hydration errors should force a client render ([#22416](react/react#22416)) //<Andrew Clark>//
- **[029fdce](react/react@029fdcebb )**: root.hydrate -> root.isDehydrated ([#22420](react/react#22420)) //<Andrew Clark>//
- **[af87f5a](react/react@af87f5a83 )**: Scheduling Profiler marks should include thrown Errors ([#22417](react/react#22417)) //<Brian Vaughn>//
- **[d47339e](react/react@d47339ea3 )**: [Fizz] Remove assignID mechanism ([#22410](react/react#22410)) //<Sebastian Markbåge>//
- **[3a50d95](react/react@3a50d9557 )**: Never attach ping listeners in legacy Suspense ([#22407](react/react#22407)) //<Andrew Clark>//
- **[82c8fa9](react/react@82c8fa90b )**: Add back useMutableSource temporarily ([#22396](react/react#22396)) //<Andrew Clark>//
- **[5b57bc6](react/react@5b57bc6e3 )**: [Draft] don't patch console during first render ([#22308](react/react#22308)) //<Luna Ruan>//
- **[cf07c3d](react/react@cf07c3df1 )**: Delete all but one `build2` reference ([#22391](react/react#22391)) //<Andrew Clark>//
- **[bb0d069](react/react@bb0d06935 )**: [build2 -> build] Local scripts //<Andrew Clark>//
- **[0c81d34](react/react@0c81d347b )**: Write artifacts to `build` instead of `build2` //<Andrew Clark>//
- **[4da03c9](react/react@4da03c9fb )**: useSyncExternalStore React Native version ([#22367](react/react#22367)) //<salazarm>//
- **[48d475c](react/react@48d475c9e )**: correct typos ([#22294](react/react#22294)) //<Bowen>//
- **[cb6c619](react/react@cb6c619c0 )**: Remove Fiber fields that were used for hydrating useMutableSource ([#22368](react/react#22368)) //<Sebastian Silbermann>//
- **[64e70f8](react/react@64e70f82e )**: [Fizz] add avoidThisFallback support ([#22318](react/react#22318)) //<salazarm>//
- **[3ee7a00](react/react@3ee7a004e )**: devtools: Display actual ReactDOM API name in root type ([#22363](react/react#22363)) //<Sebastian Silbermann>//
- **[79b8fc6](react/react@79b8fc667 )**: Implement getServerSnapshot in userspace shim ([#22359](react/react#22359)) //<Andrew Clark>//
- **[86b3e24](react/react@86b3e2461 )**: Implement useSyncExternalStore on server ([#22347](react/react#22347)) //<Andrew Clark>//
- **[8209de2](react/react@8209de269 )**: Delete useMutableSource implementation ([#22292](react/react#22292)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions e8feb11...afcb9cd

jest_e2e[run_all_tests]

Reviewed By: yungsters

Differential Revision: D31541359

fbshipit-source-id: c35941bc303fdf55cb061e9996200dc868a6f2af
@gaearon gaearon mentioned this pull request Mar 29, 2022
Add React 18 changelog #24195
Merged
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
@acdlite @zhengjitf
Implement useSyncExternalStore on server (react#22347)
46827af
Adds a third argument called `getServerSnapshot`.

On the server, React calls this one instead of the normal `getSnapshot`.
We also call it during hydration.

So it represents the snapshot that is used to generate the initial,
server-rendered HTML. The purpose is to avoid server-client mismatches.
What we render during hydration needs to match up exactly with what we
render on the server.

The pattern is for the server to send down a serialized copy of the
store that was used to generate the initial HTML. On the client, React
will call either `getSnapshot` or `getServerSnapshot` on the client as
appropriate, depending on whether it's currently hydrating.

The argument is optional for fully client rendered use cases. If the
user does attempt to omit `getServerSnapshot`, and the hook is called
on the server, React will abort that subtree on the server and
revert to client rendering, up to the nearest Suspense boundary.

For the userspace shim, we will need to use a heuristic (canUseDOM)
to determine whether we are in a server environment. I'll do that in
a follow up.
This was referenced May 19, 2024
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalaiteamlayer0#24
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1005
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#653
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1008
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#655
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#651
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1009
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#655
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#658
Open
[Snyk] Upgrade: react, react-dom https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#682
Open
This was referenced Nov 8, 2024
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1478
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1479
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1128
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#1113
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#1114
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1129
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1130
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#1116
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#1117
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1481
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1482
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#1121
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#1122
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1134
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1135
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-startup#540
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-startup#541
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#1118
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#1119
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#1126
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/layer0-astro-ssr-example#1127
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#1123
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalailayer0-astro-ssr-example#1124
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1486
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/crystalai-edgio-astro-ssr-example#1487
Open
[Snyk] Upgrade react from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1138
Open
[Snyk] Upgrade react-dom from 17.0.2 to 18.3.1 https-quantumblockchainai-atlassian-net/edgio-astro-ssr-example#1139
Open
mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
@acdlite
Implement useSyncExternalStore on server (react#22347)
61833d2
Adds a third argument called `getServerSnapshot`.

On the server, React calls this one instead of the normal `getSnapshot`.
We also call it during hydration.

So it represents the snapshot that is used to generate the initial,
server-rendered HTML. The purpose is to avoid server-client mismatches.
What we render during hydration needs to match up exactly with what we
render on the server.

The pattern is for the server to send down a serialized copy of the
store that was used to generate the initial HTML. On the client, React
will call either `getSnapshot` or `getServerSnapshot` on the client as
appropriate, depending on whether it's currently hydrating.

The argument is optional for fully client rendered use cases. If the
user does attempt to omit `getServerSnapshot`, and the hook is called
on the server, React will abort that subtree on the server and
revert to client rendering, up to the nearest Suspense boundary.

For the userspace shim, we will need to use a heuristic (canUseDOM)
to determine whether we are in a server environment. I'll do that in
a follow up.
@coderabbitai coderabbitai Bot mentioned this pull request Jun 27, 2026
refactor(capabilities): ♻️ shuffle clowns media via useSyncExternalStore, drop misplaced lib hook chicio/chicio-labs#394
Merged
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
@acdlite
Implement useSyncExternalStore on server (react#22347)
6f0f50c
Adds a third argument called `getServerSnapshot`.

On the server, React calls this one instead of the normal `getSnapshot`.
We also call it during hydration.

So it represents the snapshot that is used to generate the initial,
server-rendered HTML. The purpose is to avoid server-client mismatches.
What we render during hydration needs to match up exactly with what we
render on the server.

The pattern is for the server to send down a serialized copy of the
store that was used to generate the initial HTML. On the client, React
will call either `getSnapshot` or `getServerSnapshot` on the client as
appropriate, depending on whether it's currently hydrating.

The argument is optional for fully client rendered use cases. If the
user does attempt to omit `getServerSnapshot`, and the hook is called
on the server, React will abort that subtree on the server and
revert to client rendering, up to the nearest Suspense boundary.

For the userspace shim, we will need to use a heuristic (canUseDOM)
to determine whether we are in a server environment. I'll do that in
a follow up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rickhanlonii rickhanlonii Awaiting requested review from rickhanlonii
@sebmarkbage sebmarkbage Awaiting requested review from sebmarkbage
1 more reviewer
@salazarm salazarm salazarm approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@acdlite @sizebot @salazarm @facebook-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.