From 71a104422cb76a02bca32dd0486d1bce9df3e5d0 Mon Sep 17 00:00:00 2001 From: Soam Desai Date: Wed, 16 Sep 2026 12:01:00 -0700 Subject: [PATCH] fix: route from `/` once the persisted store has hydrated Opening the simulator flashed the identity picker before landing on the active identity. The redirect effect on `/` read `activeIdentityID` from the React snapshot, which is the pre-hydration state during the first render, so it pushed `/select-id` and then, one render later, `/id/`. Decide once from the live store after `persist` has hydrated, mirroring the seeding fix, and use `replace` so the redirect page stays out of history and Back never bounces through it. Co-Authored-By: Claude Fable 5.1 --- src/pages/index.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index c096d94..fc20d94 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -34,20 +34,24 @@ export default function Home() { return useIdentityStore.persist.onFinishHydration(seedIfEmpty); }, [generateFirstFiveIdentities]); + // Route once, from the live store after hydration, for the same reason as + // above: deciding on the pre-hydration snapshot sent every load through + // /select-id before landing on the active identity. `replace` keeps this + // redirect page out of the history, so Back never bounces through it again. useEffect(() => { if (!router.isReady || connectUrl) return; - if ( - activeIdentityID != null && - !router.pathname.includes(`/id/${activeIdentityID}`) - ) { - console.log("Redirecting to active identity:", activeIdentityID); - void router.push(`/id/${activeIdentityID}`); - } else if (!activeIdentityID && !router.pathname.includes("/select-id")) { - console.log("Redirecting to select identity"); - void router.push("/select-id"); + const redirect = () => { + const { activeIdentityID: activeId } = useIdentityStore.getState(); + void router.replace(activeId ? `/id/${activeId}` : "/select-id"); + }; + + if (useIdentityStore.persist.hasHydrated()) { + redirect(); + return; } - }, [activeIdentityID, connectUrl, router]); + return useIdentityStore.persist.onFinishHydration(redirect); + }, [connectUrl, router]); useEffect(() => { if (!router.isReady) return;