/** * Where the client navigation in flight is going (BUG-1040). * * Next's app router renders the next page first and writes the address bar * afterwards (HistoryUpdater, an insertion effect). A page that decides its * first frame from the URL — Home's warm return reads `?new=1` / `?c=` — would * otherwise read the page it is leaving. `AppLink` and `navigateAppPath` note * the href here just before the router starts; the page takes it once. * * Memory only, no dependencies (it ships with the shared sidebar). */ const MAX_AGE_MS = 10_000; let target: { href: string; at: number } | null = null; export function noteClientNavigationTarget(href: string): void { if (!href.startsWith("/") || href.startsWith("//")) return; target = { href, at: Date.now() }; } /** The noted href (then forgotten), or null when none is recent enough to trust. */ export function takeClientNavigationTarget(now = Date.now()): string | null { const noted = target; target = null; if (!noted || now - noted.at > MAX_AGE_MS) return null; return noted.href; }