Repository navigation
Make redirects no-store - #185
Merged
Merged
Conversation
Deploying nemar-website with
|
| Latest commit: |
cb69e64
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aa2505ae.nemar-website.pages.dev |
| Branch Preview URL: | https://fix-issue-183-redirect-no-st.nemar-website.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #183.
Cross-host and retired-path redirects carried no
Cache-Control, so a bare301was heuristically cacheable — and browsers cache permanent redirects aggressively and persistently.Why it matters
Both redirect decisions encode a route classification — a deploy-time choice — not a fact about the world. When that classification changes, a cached redirect keeps sending clients to the old answer, and it lives in the one cache we can't purge.
That already happened.
/api/noticeswas classified marketing-only and 301'd offapp.nemar.orgfor ~20 minutes between #179 and #182. Any browser that ran the banner's fetch in that window can hold the redirect indefinitely, so the server-side fix never reaches it — the banner stays broken there until a hard reload.Nothing user-visible resulted (the window was short and there are no notices yet), but the mechanism turns any future route reclassification into a per-user cache problem instead of a deploy.
The existing comment and test had the right intent, backwards
and a test named
"doesn't set Cache-Control on cross-host redirects (deploy churn safety)"asserting the header was absent.The hazard named there is exactly right — pinning clients through a re-balance — but omitting the header is what causes it. The comment guards the CDN and leaves the browser, which is both the likelier cache and the unpurgeable one. The test locked that in.
Change
A single
NO_STORE_HEADERapplied to both redirect branches. Cost is nil: empty-body responses on paths that are, by definition, being requested on the wrong host.Applied to retired-path redirects too. Those are a genuinely permanent move so caching them is defensible — but they're low-traffic legacy links by definition, and the same "this is a deploy-time mapping" argument applies if one is ever un-retired. Not worth the asymmetry for the saving.
Testing
854 passing, 38 in
middleware.test.ts(4 new/rewritten). typecheck, lint, build clean.The old test is rewritten to assert
no-storeand carries the reasoning so the intent can't invert again. Added coverage for the non-GET (307) path, the retired-path branch, and thatisPublicCacheablestill rejects these so the edge cache keeps ignoring them.Verified the tests actually bite: removing
NO_STORE_HEADERfrom the cross-host branch fails 2 tests rather than passing silently.