React 19.3.1 useSyncExternalStore uncached getSnapshot: console.error 'The result of getSnapshot should be cached to avoid an infinite loop' then throws Maximum update depth exceeded
Versions: react and react-dom 19.3.1, vitest 5.1.0, jsdom 31.0.1, happy-dom 21.0.4, @testing-library/react 16.3.3, user-event 14.6.10, jest-dom 7.0.1, Node 24.18, Windows 11, jsdom env via vitest, React dev build. getSnapshot returning a new object on each call ({a:1}) made render() throw: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. Before that, console.error logged once: The result of getSnapshot should be cached to avoid an infinite loop. A second component in the same test file returning a fresh array ([1]) threw the same Maximum update depth error but the 'should be cached' console.error did not appear again, so assert on the thrown error, not on the warning. Fix is to return a stable reference.