Repository navigation
fix(useResponsive): return a stable server snapshot - #14
Merged
Merged
Conversation
`_getServerSnapshot` allocated a fresh `{ width: 1280, height: 900 }` on every
call. React requires the server snapshot to be a cached reference — a new
object each read means the snapshot always compares unequal, which is what the
"result of getServerSnapshot should be cached to avoid an infinite loop"
warning exists to catch. useResponsive backs Box/Stack/Grid, so this runs many
times per server-rendered page.
Scope, honestly: this is a real contract violation and worth fixing on its own
merits, but it did NOT resolve that warning in the consuming app. It still
fires after rebuilding this package, wiping the Metro/Expo caches and doing a
cold rebuild, and this is the only useSyncExternalStore call site in the
workspace — so there is another source, most likely inside react-native-web or
expo-router. Tracked separately in UNI-Construct; do not close that on this.
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
Jul 30, 2026
Bumps @scaffald/ui to pick up Scaffald/ui#14, which had been open and unmerged for a week. `_getServerSnapshot` returned a fresh `{ width, height }` object on every call, so React saw the snapshot change on every read — exactly what "The result of getServerSnapshot should be cached to avoid an infinite loop" describes. useResponsive backs Box/Stack/Grid, so it runs many times per SSR page. Latent-bug removal: the warning does not currently reproduce on main with clean caches (full bisect in #438), but returning an unstable reference from getServerSnapshot violates React's documented contract regardless, and the apex renders server-side. Refs #438 Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_getServerSnapshotallocated a fresh{ width: 1280, height: 900 }on every call:React requires the server snapshot to be a cached reference. A new object each read compares unequal every time, which is precisely what the "The result of getServerSnapshot should be cached to avoid an infinite loop" warning exists to catch.
useResponsivebacksBox/Stack/Grid, so it runs many times per server-rendered page.Hoisted to a module constant. One line, no behaviour change.
Scope — please read before assuming this closes anything
This is a genuine contract violation and worth fixing on its own merits, but it did not resolve that warning in the consuming app. It still fires after:
dist.expo, andnode_modules/.cachenode_modules/@scaffald/uisymlinks resolve to the fixed copyAnd this is the only
useSyncExternalStorecall site in the entire workspace. So there is at least one more source — most likely insidereact-native-weborexpo-routerinternals rather than our code.I'd rather land the correct code than leave a known-wrong snapshot in place, but I don't want the commit message implying a fix it didn't deliver. Tracked separately in UNI-Construct.