Fix nacFetch/afpFetch cache options: seconds TTL and real cache tags - #1186
Merged
Conversation
The default `revalidate` passed `24 * 60 * 60 * 1000`, but Next reads
`next.revalidate` in seconds — that is ~1000 days, not the one day the
comment claimed. Vercel's data cache is per-deployment, so in practice
`getAvalancheCenterMetadata` and `getAllAvalancheCenterCapabilities` held
upstream data until the next redeploy. A forecaster who added or renamed a
zone, or changed widget config in the NAC dashboard, would not see it on
AvyWeb until web shipped again.
`tags` was also spread as a bare array into the `next` object, which sets
numeric keys (`{ 0: 'tag' }`) rather than `tags`. The fetch was left
untagged, so `revalidateTag` could never invalidate it. Latent today — no
caller passes `tags` — but it fails silently for whoever adds the first one.
Fixes #1185
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The two functions are near-identical but had drifted: their fetch init was duplicated inline, which is how the seconds/milliseconds and bare-array-tags bugs came to exist in both copies independently. Extract the shared `fetchInit` so there is one place to get it right. Also adds `noStore` to both, for responses too large for the 2MB data cache. No caller needs it yet, but it belongs in the shared helper rather than being bolted onto one of the pair later. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
Preview deployment: https://busbykxfix-fetch-cache-options.preview.avy-fx.org |
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.
Description
nacFetchandafpFetchdefaultednext.revalidateto24 * 60 * 60 * 1000, but Next reads that field in seconds — that's ~1000 days, not the one day the comment claimed, so upstream NAC data was effectively pinned until the next deploy. They also spreadtagsinto thenextobject as a bare array, which sets numeric keys ({ 0: 'tag' }) rather thantags, leaving every fetch untagged andrevalidateTaga silent no-op. Both bugs existed in two near-identical inline copies, so this also extracts the sharedfetchInithelper that made them possible.Related Issues
Fixes #1185
Key Changes
revalidatenow defaults to24 * 60 * 60(seconds) in both functions. This is what unsticksgetAvalancheCenterMetadata(zones, timezone, widget config) andgetAllAvalancheCenterCapabilities— a forecaster who adds or renames a zone, or changes widget config in the NAC dashboard, no longer has to wait for a redeploy to see it.tagsis spread as{ tags: options.tags }, sorevalidateTagactually applies. Latent today (no caller passestags), but it fails silently for whoever adds the first one.fetchInit(options), shared by both functions, and addednoStoreto both for responses too large for the 2MB data cache. No caller needsnoStoreyet; it belongs in the shared helper rather than being bolted onto one of the pair later.7cafd29is the bug fix alone,230919cis the refactor.How to test
pnpm test— new__tests__/server/nacFetchCacheOptions.server.test.tsruns as adescribe.eachover both functions so they can't drift again, covering default TTL in seconds, explicitcachedTimepassthrough,cachedTime: false,next.tagspopulated, tags omitted when absent/empty, andnoStore→cache: 'no-store'. These are load-bearing: temporarily reverting the fix fails 4 of them. Full suite passes (71 suites / 627 tests), along withpnpm tsc,pnpm lint,pnpm drift:check, andpnpm fallow:audit.Screenshots / Demo video
N/A — no user-visible UI change.
Migration Explanation
N/A — no schema or migration changes.
Future enhancements / Questions
N/A
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.