Skip to content

Deadlines on the catalog client, and the legacy dataset rewrite - #192

Merged
neuromechanist merged 1 commit into
mainfrom
fix/resolve-canonical-deadline
Jul 25, 2026
Merged

neuromechanist merged 1 commit into
mainfrom
fix/resolve-canonical-deadline

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Two changes on the path legacy citation URLs will travel after the apex cutover (#190). The first is a prerequisite for the second.

1. Deadlines on src/lib/api.ts (website#173)

All four fetches passed signal: init.signal, which is undefined whenever the caller omits it — and no page caller passes one. A try/catch covers a request that fails; it does not cover one that opens and never writes a response. That promise never settles, so there is nothing to catch.

resolveCanonical is the one that mattered: it runs during SSR of every ds* dataset page, which after cutover is the path every legacy citation URL travels. A hung upstream there stalls the render rather than degrading it.

Added the same resolveSignal() pattern the admin clients already use, plus an optional timeoutMs.

Scope: api.ts only. The same bug class remains in admin-api.ts, collaborators-api.ts, dashboard-api.ts and dir-listing.ts — 10 more instances, all on authenticated surfaces with smaller blast radius. Those stay under #173 rather than being swept into a PR about the citation path.

2. Legacy dataset URL rewrite (#190 §2)

After cutover nemar.org points at this build, so /dataexplorer/detail lands here with no route and would 404. Handled in middleware.ts — where the other redirects live, and the only place with both the query string and the Referer header.

Two audiences want opposite things from the same URL:

arriving from goes to status
ww1 (mid-session on the legacy site) back to ww1, query preserved 302
anywhere else, or no referer /dataset/<id> on the new site 301

302 for the ww1 bounce is deliberate. ww1 retires, and a cached permanent redirect would outlive it with no way to reach the clients holding it — the hazard #183 was filed for. The move to the new site is genuinely permanent, so that one is 301. Both carry no-store, which matters doubly here because the response varies by Referer and caching it would serve one audience's answer to the other.

Absent Referer means "new site", deliberately. It is unreliable — stripped by privacy modes, absent on typed and bookmarked navigation — so the default has to be the citation case, which is the one that must not break.

The id is passed through untranslated

/dataset/ds007964 already resolves to /dataset/on007964, via resolveCanonical doing a real catalog lookup (GET /datasets/resolve/<sourceId>). That is better than the prefix swap originally proposed in #190: it declines when no mirror exists instead of confidently redirecting to an on id that doesn't exist. Re-deriving the mapping in the rewrite would duplicate that rule and could disagree with it, so this layer only changes the path shape.

It also means the rewrite works unchanged for nm###### (native, no mapping) and any future prefix.

Testing

889 passing (17 new), typecheck / lint / build clean.

Unit coverage for the referrer asymmetry, the 301-vs-302 distinction, malformed and lookalike referers (ww1.nemar.org.evil.test must not bounce), id pass-through for ds/nm/on, path-encoding of a hostile id, the no-id fallback, and trailing-slash/case tolerance. Plus middleware-level tests covering the wiring, since the pure function can't see the Referer header.

Verified end to end against a running server:

no referer                     301 -> /dataset/ds007964      cache-control: no-store
Referer: ww1.nemar.org         302 -> https://ww1.nemar.org/dataexplorer/detail?dataset_id=ds007964
Referer: ww1.nemar.org.evil    301 -> /dataset/ds007964      (correctly not treated as ww1)
no dataset_id                  302 -> /discover
/discover                      200                            (unaffected)

Note

This ships before the cutover, which is safe: /dataexplorer/* is not a route on this build today, so the rewrite is inert on ww2 until the apex points here. Landing it early means the cutover is a DNS-and-constants change rather than a code change.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

@neuromechanist
neuromechanist merged commit 242e4db into main Jul 25, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the fix/resolve-canonical-deadline branch July 25, 2026 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant