Skip to content

fix: serve HTML with no-store so deploys aren't stale until a hard refresh - #48

Merged
codingshreyash merged 1 commit into
mainfrom
fix/stale-html-cache
Aug 2, 2026
Merged

fix: serve HTML with no-store so deploys aren't stale until a hard refresh#48
codingshreyash merged 1 commit into
mainfrom
fix/stale-html-cache

Conversation

@codingshreyash

@codingshreyash codingshreyash commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Problem

The site kept opening with an old build and only showed the current version after a hard refresh — on every device, and unaffected by clearing cookies.

Root cause is HTTP caching of the HTML document (there is no service worker). The live CDN serves the new build, so the stale copy lives in each browser's local cache. netlify.toml tried to send no-store, but Next.js hardcodes a cacheable Cache-Control on statically-prerendered pages and overrides any header set via netlify.toml, next.config.js, or middleware. The only reliable way to emit no-store is dynamic rendering.

Changes

  • app/layout.tsxexport const dynamic = "force-dynamic" in the root layout cascades to every route. Documents are now served Cache-Control: no-store, ...; hashed /_next/static assets keep public, max-age=31536000, immutable.
  • netlify.toml — replaced the ineffective, mis-scoped for = "/*" block with a rule that only reasserts immutable caching for /_next/static/*.
  • app/page.tsx + app/globals.css — fixed the light-mode flash: the hero gradient is now driven by CSS keyed on the .dark class (set pre-paint) instead of React state that started in light mode. Removed the client-only hooks; the home page is now a server component.

Verification

  • Production build passes; all routes are dynamic (λ); lint clean; tests pass.
  • Locally (next start): documents return no-store, hashed assets stay immutable.
  • Visually confirmed both light and dark render with no flash.

Tradeoff

Every page is now server-rendered per request instead of served as cached static HTML — slightly slower first byte and more Netlify function calls. Negligible for a wiki this size; it's the price of guaranteeing no page is ever stale.

Before merging

Confirm on the Netlify deploy preview that the header actually reaches the browser (Netlify is the final authority):

curl -sSI <deploy-preview-url> | grep -i cache-control
# expect: no-store  (not "max-age=0, must-revalidate")

@netlify

netlify Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploy Preview for pittcswiki ready!

Name Link
🔨 Latest commit 3908608
🔍 Latest deploy log https://app.netlify.com/projects/pittcswiki/deploys/6a6fcd6ed9db0a00082b4af1
😎 Deploy Preview https://deploy-preview-48--pittcswiki.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

…fresh

Pages were served as static HTML with a cacheable Cache-Control, so browsers
kept showing an old build until a manual hard refresh (across all devices,
independent of cookies). Next.js hardcodes a cacheable header on statically
prerendered pages and ignores overrides from netlify.toml, next.config.js, and
middleware, so the only reliable fix is dynamic rendering.

- Force dynamic rendering in the root layout so every document is served with
  Cache-Control: no-store (Next.js emits this for dynamic routes). Hashed
  /_next/static assets keep their immutable cache.
- Scope netlify.toml headers to reassert immutable caching for build assets
  instead of a no-op blanket rule on /*.
- Fix the light-mode flash on the home page: drive the hero gradient from CSS
  keyed on the .dark class (set pre-paint) instead of React state that starts
  in light mode, removing the client-only hooks.
@codingshreyash
codingshreyash merged commit 72b32fd into main Aug 2, 2026
6 of 7 checks passed
@codingshreyash
codingshreyash deleted the fix/stale-html-cache branch August 2, 2026 23:11
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