mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
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:
parent
48acb8c640
commit
d7f9c3ed0c
@ -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 }) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user