Skip to content

Commit 5871779

Browse files
committed
Fix useSyncExternalStore detection for React 19+
The version check used startsWith('18') which excluded React 19, causing fallback to legacy useState+useLayoutEffect subscription. This caused tearing in concurrent rendering scenarios. Fixes #1387
1 parent 66fd0e5 commit 5871779

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'react-virtuoso': patch
3+
---
4+
5+
Fix useSyncExternalStore detection for React 19+
6+
7+
The version check used `startsWith('18')` which excluded React 19, causing it to fall back to the legacy useState+useLayoutEffect subscription path. This could cause tearing issues in concurrent rendering scenarios. Changed to `parseInt(React.version) >= 18` to correctly use useSyncExternalStore for React 18 and above.

‎packages/react-virtuoso/src/react-urx/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export function systemToComponent<SS extends AnySystemSpec, M extends SystemProp
299299
return value
300300
}
301301

302-
const useEmitterValue = React.version.startsWith('18') ? useEmitterValue18 : useEmitterValueLegacy
302+
const useEmitterValue = parseInt(React.version) >= 18 ? useEmitterValue18 : useEmitterValueLegacy
303303

304304
const useEmitter = <K extends keyof S, V = S[K] extends Stream<infer R> ? R : never>(key: K, callback: (value: V) => void) => {
305305
const context = React.useContext(Context)

0 commit comments

Comments
 (0)