Description
I tried to migrate an app from React 18 beta and useMutableSource to RC0 and useSyncExternalStore. Everything worked fine, except:
- If a component has more than one useSyncExternalStore hooks
- And if the component has useState hook
- And if the useState's setter is invoked
- And if the mode is production
- Then React explodes 100% repeatably
The exact 'explosion' seems to depend on where/how useState setter is invoked and/or what other hooks are used. In some cases useRef starts returning 'undefined' and in some cases useCallback starts throwing internally "typeError: Cannot read property 'length' of undefined".
The above is in our real app - I haven't tried isolated repro. Also in our app, the two useSyncExternalStore hooks are subscribed to different stores, not sure if that is related or relevant.
Maybe you could quickly add the above case (2x useSyncExternalStore + useState) to your existing tests, and if it doesn't reproduce the bug, then I can do a minimal isolated repro?