"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { LAST_PAGE_KEY, isRecordable, restoreCandidates } from "@/lib/last-page"; // Where you were, as a LINK rather than a redirect. The dashboard is a page in // its own right now, so / no longer replaces itself with your last URL -- it // offers it. Same storage, same guard, same HEAD-probed walk-up as the old // restore, so a stale URL degrades to its parent instead of to a 404. export default function ResumeChip() { const [target, setTarget] = useState(null); useEffect(() => { let done = false; (async () => { let stored: string | null = null; try { stored = localStorage.getItem(LAST_PAGE_KEY); } catch { stored = null; } if (!stored || !isRecordable(stored)) return; for (const url of restoreCandidates(stored)) { if (done) return; let alive = false; try { const res = await fetch(url, { method: "HEAD", cache: "no-store" }); alive = res.status !== 404; } catch { alive = false; } if (alive) { setTarget(url); return; } } // Nothing down to the floor answered. A URL that can never resolve must // not cost a probe on every open, so it goes. try { localStorage.removeItem(LAST_PAGE_KEY); } catch { /* nothing to clean up */ } })(); return () => { done = true; }; }, []); if (!target) return null; return ( resume {target} → ); }