test(ui): stabilize fresh start hydration
This commit is contained in:
@@ -237,16 +237,9 @@ export default function ScenarioForm() {
|
|||||||
|
|
||||||
const branchScoped = useBranchScopedFixture();
|
const branchScoped = useBranchScopedFixture();
|
||||||
// Toggle to control when the experiment view is visible vs production
|
// Toggle to control when the experiment view is visible vs production
|
||||||
const [showExperimentView, setShowExperimentView] = useState(
|
// Always start false for SSR-safe deterministic first render.
|
||||||
typeof window !== "undefined" ? (() => {
|
// sessionStorage reads are deferred to useEffect (after mount).
|
||||||
const saved = sessionStorage?.getItem("ce-show-experiment");
|
const [showExperimentView, setShowExperimentView] = useState(false);
|
||||||
// Only default to true if user explicitly toggled ON (saved === "true")
|
|
||||||
// or has an active investigation context (session exists with situationGraph)
|
|
||||||
if (saved === "true") return true;
|
|
||||||
const session = getSession();
|
|
||||||
return Boolean(session?.situationGraph);
|
|
||||||
})() : false,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Use fixture branches as the authoritative source when available
|
// Use fixture branches as the authoritative source when available
|
||||||
const BRANCHES = useMemo(() => branchScoped.getBranches(), [branchScoped]);
|
const BRANCHES = useMemo(() => branchScoped.getBranches(), [branchScoped]);
|
||||||
@@ -309,6 +302,20 @@ export default function ScenarioForm() {
|
|||||||
setStatus("success");
|
setStatus("success");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/* Restore experiment view preference from storage (after hydration) ─ */
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
const savedExp = sessionStorage?.getItem("ce-show-experiment");
|
||||||
|
if (savedExp === "true") {
|
||||||
|
setShowExperimentView(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const session = getSession();
|
||||||
|
if (session?.situationGraph) {
|
||||||
|
setShowExperimentView(true);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
/* Restore facilitator dismiss preference (Experiment 05) ─── */
|
/* Restore facilitator dismiss preference (Experiment 05) ─── */
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window === "undefined") return;
|
if (typeof window === "undefined") return;
|
||||||
|
|||||||
Reference in New Issue
Block a user