Comments (4)
I'm not seeing any error when opening https://codesandbox.io/s/usesyncexternalstore-suspense-bug-lyoc03?file=/src/App.js:217-241.
Did you maybe change the codesandbox in the meantime?
from react.
@eps1lon Hi, I haven't updated the code in Codesandbox. I'm not entirely sure why the error message isn't showing up in the Codesandbox environment's console maybe it has something to do with how this error is logged, but you can still see the error by checking out the browser console. By looking at the Codesandbox environment's browser console or by opening the direct browser view link: https://lyoc03.sse.codesandbox.io/. Here's a screenshot if that helps:
from react.
Ah gotcha, error didn't display in codesandbox console.
This was fixed in #25692. The next stable release should have this. In the meantime, you can verify it by using react@next, @react-dom@next
from react.
@eps1lon Tested it in the @next
version. The error logging is fixed but the Suspense SSR component behaviour looks unexpected.
React version: 18.3.0-next-a8875eab7-20230310
Steps To Reproduce
- Use
Suspense
SSR anduseSyncExternalStore
in the same component. - Ensure that the
serverSnapshot
andsnapshot
inuseSyncExternalStore
are different. - Suspended component on the client side fully rerenders. Falls into a fallback state and then renders its content.
Link to code example: https://codesandbox.io/p/sandbox/usesyncexternalstore-suspense-bug-forked-drm325
The current behavior
The suspended component on the client side fully rerenders. Falls into a fallback state and then renders its content. Due to a mismatch between serverSnapshot
and snapshot
when using Suspense
and useSyncExternalStore
in the same component.
The expected behaviour
The suspended component doesn't do a full rerender(falls into a fallback state and then renders its content):
- if the
serverSnapshot
andsnapshot
are identical. - if the
useSyncExternalStore
has a mismatch betweenserverSnapshot
andsnapshot
and is used in a component without aSuspense
boundary.
I assume the expected behaviour should be: the suspended component shouldn't do a full rerender(fall into a fallback state and then render its content) when useSyncExternalStore
is used with Suspense
in the same component. I assume it shouldn't fall into a fallback state it should just do a rerender.
Additional context
One use case when snapshot
and serverSnapshot
may be different:
The latest version of the react-redux
library under the hood uses useSyncExternalStore
. For example, if we have 2 different hydrateRoot
entries for header
and for body
and we need them to share the same redux store. One issue that occurs with this setup is that if the header
is hydrated earlier than the body
the header
will start firing store updates while the body
is still hydrating and this will cause serverSnapshot
and snapshot
to be different while the body
is still hydrating and because of this suspended SSR components will fall into the fallback state if redux state selector and Suspense boundary are used in the same component.
from react.
Related Issues (20)
- Bug: Search functionality not working correctly on react.dev in Safari on iOS real device (iPhone 12 Pro) HOT 2
- Bug:
- Google Translate causing "Text content does not match server-rendered HTML" HOT 1
- Bug: useFormState formAction becomes null in strict mode HOT 1
- Bug: Source is not showing in 5.0.2 HOT 8
- Question and suggest: The official identifier of Server Compnoent and Client Component HOT 3
- Bug: when installing the application, the old version of "react-scripts" is installed HOT 1
- Bug: Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. HOT 4
- Bug: optimistic state (useOptimistic) shows both optimistic and returned from server data when running several async actions HOT 6
- [DevTools Bug]: React Profiler reports higher hook numbers than shown in Components HOT 2
- about the react performance (how to improve it) HOT 2
- Bug: use() hook HOT 4
- Bug: Flight (RSC) examples are not accessible HOT 1
- useMemo reruns when the dependencies not changed when memoised value is a fn HOT 3
- Bug: [Flight] Async server components in `ai/rsc` not serialized correctly HOT 1
- Bug: React Dev tools extension showing wrong source file path on inspection HOT 4
- Bug: Using the hook useDeferredValue - Suspense fallback didn't show the contents HOT 4
- Bug: react-intl formatMessage cannot format message with param that neat by Single quotation mark HOT 3
- custom use directives + using closure serializer
- In react fiber, is didReceiveUpdate related to dirty checking?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.