Bug: Unexpected Suspense SSR Component Behavior with useSyncExternalStore in React 18.3.0-next: Rerender and Fallback State Issues #26477
Labels
Resolution: Stale
Automatically closed due to inactivity
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
The bug relates to #26318. In React 18.2.0 this case prints an error but the functionality seems unexpected. In 18.3.0-next-9c54b29b4-20230322 it doesn't print an error, but unexpected functionality still exists.
React version: 18.3.0-next-9c54b29b4-20230322
Steps To Reproduce
Suspense
SSR anduseSyncExternalStore
in the same component.serverSnapshot
andsnapshot
inuseSyncExternalStore
are different.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
andsnapshot
when usingSuspense
anduseSyncExternalStore
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):
serverSnapshot
andsnapshot
are identical.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 withSuspense
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
andserverSnapshot
may be different:The latest version of the
react-redux
library under the hood usesuseSyncExternalStore
. For example, if we have 2 differenthydrateRoot
entries forheader
and forbody
and we need them to share the same redux store. One issue that occurs with this setup is that if theheader
is hydrated earlier than thebody
theheader
will start firing store updates while thebody
is still hydrating and this will causeserverSnapshot
andsnapshot
to be different while thebody
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.The text was updated successfully, but these errors were encountered: