fix: stabilize useSyncExternalStore snapshots to prevent infinite re-renders

getHealthyDevEnvironmentSnapshot and getServerDevEnvironmentHealthSnapshot
returned new object references on every call, violating useSyncExternalStore's
contract that getSnapshot must return a referentially stable value when the
store hasn't changed.

On non-development environments (like staging), React's passive effect
consistency check detects the reference mismatch between render and commit,
forces a re-render, which produces another new object, triggering error #185
(Maximum update depth exceeded).

Fix: hoist snapshot objects to module-level constants.
Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>
This commit is contained in:
Devin AI 2026-05-20 00:20:26 +00:00
parent 48acb8c640
commit d7f9c3ed0c

View File

@ -100,16 +100,18 @@ function getDevEnvironmentHealthSnapshot() {
return devEnvironmentHealthSnapshot;
}
const SERVER_DEV_ENVIRONMENT_HEALTH_SNAPSHOT: DevEnvironmentHealthSnapshot = { status: "checking" };
function getServerDevEnvironmentHealthSnapshot(): DevEnvironmentHealthSnapshot {
return { status: "checking" };
return SERVER_DEV_ENVIRONMENT_HEALTH_SNAPSHOT;
}
function subscribeHealthyDevEnvironment(_callback: () => void) {
return () => {};
}
const HEALTHY_DEV_ENVIRONMENT_SNAPSHOT: DevEnvironmentHealthSnapshot = { status: "healthy" };
function getHealthyDevEnvironmentSnapshot(): DevEnvironmentHealthSnapshot {
return { status: "healthy" };
return HEALTHY_DEV_ENVIRONMENT_SNAPSHOT;
}
function DevEnvironmentStoppedScreen(props: { restartCommand: string }) {