v4: a link from one dump's page to another's opens that dump — it reloaded the one on screen: the page stays mounted when its path changes, and for one render the old dump was still loaded under the new path, so useCanonicalPath took that path for a former one and put the old dump's back, which was then fetched again. A related dump's link did it, and so did any dump link in a note or a comment. The page now drops the dump on screen in the render that sees a path naming another, as usePlaylist and useProfile do. The dump handed over by DumpEdit or a title edit goes with it, so that coming back to its path fetches it instead of matching that snapshot and loading forever.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-10-10 08:34:32 +00:00
parent 7dd00068df
commit dde0232acb
2 changed files with 82 additions and 2 deletions

View File

@@ -79,7 +79,7 @@ export function Dump(): React.JSX.Element {
const navigate = useNavigate();
// Taken once, since it stays in the history entry, where a reload or Back
// would show that snapshot forever. It is cleared from there below.
const [handedOver] = useState(
const [handedOver, setHandedOver] = useState(
() => (location.state as { dump?: Dump } | null)?.dump ?? null,
);
const preloaded = isAt(handedOver, username, slug) ? handedOver : null;
@@ -95,6 +95,19 @@ export function Dump(): React.JSX.Element {
preloaded ? { status: "loaded", dump: preloaded } : { status: "loading" },
);
const loadedDump = dumpState.status === "loaded" ? dumpState.dump : null;
// The path last rendered. One that names another dump, as a related dump's
// link does, drops the dump on screen in the same render: left for the
// fetch below to drop, useCanonicalPath would first put its path back in
// the URL. The dump handed over goes with it, so that coming back to its
// path fetches it.
const [target, setTarget] = useState({ username, slug });
if (target.username !== username || target.slug !== slug) {
setTarget({ username, slug });
if (!isAt(loadedDump, username, slug)) {
setHandedOver(null);
setDumpState({ status: "loading" });
}
}
useCanonicalPath(loadedDump && dumpUrl(loadedDump));
// The dump on screen, which a path it was just given, by useCanonicalPath or
// a slug edited elsewhere, needn't fetch again.