Skip to content

Fix nacFetch/afpFetch cache options: seconds TTL and real cache tags - #1186

Merged
busbyk merged 2 commits into
mainfrom
busbyk/fix-fetch-cache-options
Aug 12, 2026
Merged

Fix nacFetch/afpFetch cache options: seconds TTL and real cache tags#1186
busbyk merged 2 commits into
mainfrom
busbyk/fix-fetch-cache-options

Conversation

@busbyk

@busbyk busbyk commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

nacFetch and afpFetch defaulted next.revalidate to 24 * 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 spread tags into the next object as a bare array, which sets numeric keys ({ 0: 'tag' }) rather than tags, leaving every fetch untagged and revalidateTag a silent no-op. Both bugs existed in two near-identical inline copies, so this also extracts the shared fetchInit helper that made them possible.

Related Issues

Fixes #1185

Key Changes

  • revalidate now defaults to 24 * 60 * 60 (seconds) in both functions. This is what unsticks getAvalancheCenterMetadata (zones, timezone, widget config) and getAllAvalancheCenterCapabilities — 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.
  • tags is spread as { tags: options.tags }, so revalidateTag actually applies. Latent today (no caller passes tags), but it fails silently for whoever adds the first one.
  • Extracted fetchInit(options), shared by both functions, and added noStore to both for responses too large for the 2MB data cache. No caller needs noStore yet; it belongs in the shared helper rather than being bolted onto one of the pair later.
  • Commits are split: 7cafd29 is the bug fix alone, 230919c is the refactor.

How to test

pnpm test — new __tests__/server/nacFetchCacheOptions.server.test.ts runs as a describe.each over both functions so they can't drift again, covering default TTL in seconds, explicit cachedTime passthrough, cachedTime: false, next.tags populated, tags omitted when absent/empty, and noStorecache: 'no-store'. These are load-bearing: temporarily reverting the fix fails 4 of them. Full suite passes (71 suites / 627 tests), along with pnpm tsc, pnpm lint, pnpm drift:check, and pnpm 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


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

busbyk and others added 2 commits August 12, 2026 11:49
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>
@github-actions

Copy link
Copy Markdown
Contributor

@busbyk
busbyk added this pull request to the merge queue Aug 12, 2026
Merged via the queue into main with commit 6053afc Aug 12, 2026
12 checks passed
@busbyk
busbyk deleted the busbyk/fix-fetch-cache-options branch August 12, 2026 21:15
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.

nacFetch/afpFetch cache options: default TTL is milliseconds in a seconds field, and tags is spread as a bare array

1 participant