refactor(isr): centralise HIT/STALE/MISS + Cache-Control decision in isr-decision.ts#1883
Open
Divkix wants to merge 2 commits into
Open
refactor(isr): centralise HIT/STALE/MISS + Cache-Control decision in isr-decision.ts#1883Divkix wants to merge 2 commits into
Divkix wants to merge 2 commits into
Conversation
…isr-decision.ts Add server/isr-decision.ts as the single owner of the ISR cache policy decision across all four call sites (app-page-cache, app-route-handler, pages-page-data, dev-server). Every cache disposition, background-regen flag, and Cache-Control string now flows through decideIsr() or its MISS helpers. Also eliminate all hardcoded Cache-Control literals outside cache-control.ts (NEVER_CACHE_CONTROL, NO_STORE_CACHE_CONTROL, and raw s-maxage strings in dev-server.ts, pages-page-response.ts, pages-page-handler.ts). One deliberate behaviour change: dev STALE responses now emit s-maxage=0, stale-while-revalidate (matching prod Pages Router) instead of s-maxage=<revalidate>, stale-while-revalidate. This closes a dev/prod parity gap that was masked by the duplication. Closes cloudflare#1783
commit: |
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 #1783
What
Adds
server/isr-decision.tsas the single owner of the ISR cache policy decision. All four call sites that previously re-derived HIT/STALE/MISS disposition, background-regen scheduling, andCache-Controlstring selection now delegate todecideIsr()or its MISS helpers.Also eliminates all hardcoded
Cache-Controlliterals outsidecache-control.ts— raw strings like"private, no-cache, no-store, max-age=0, must-revalidate"that were copy-pasted acrossdev-server.ts,pages-page-response.ts, andpages-page-handler.ts.Call sites migrated
server/app-page-cache.ts— removed localbuildAppPageCacheControlwrapperserver/app-route-handler-response.ts— removed localbuildRouteHandlerCacheControl; cached responses usedecideIsr(kind:"app-route"), fresh MISS responses usebuildAppRouteMissIsrCacheControl(preserves therevalidate=0→NEVER andInfinity→STATIC gates)server/pages-page-data.ts—buildPagesCacheResponsedelegates todecideIsr(kind:"pages")server/dev-server.ts— all four inline literals replacedDeliberate behaviour change
Dev STALE responses now emit
s-maxage=0, stale-while-revalidate(matching prod Pages Router and the canonicalbuildCachedRevalidateCacheControlhelper) instead ofs-maxage=<revalidate>, stale-while-revalidate. The old value incorrectly told downstream caches that a stale-served payload was freshly cacheable — a dev/prod parity gap that was masked by the duplication.Equivalence
Every other migrated path emits the same header as before. The full per-call-site equivalence table is in the
isr-decision.tsmodule doc comment.Tests
tests/isr-decision.test.ts— 33 new unit tests covering all dispositions, router kinds,0/Infinityspecial cases, metadata fallback semantics, and the MISS helpersapp-page-cache,app-route-handler-cache,app-route-handler-response,pages-page-data,isr-cache,cache-control,features