Skip to content

fix: auto-reload on SW activation to prevent stale bundle 404s#1061

Merged
koala73 merged 1 commit intomainfrom
worktree-declarative-gliding-bird
Mar 5, 2026
Merged

fix: auto-reload on SW activation to prevent stale bundle 404s#1061
koala73 merged 1 commit intomainfrom
worktree-declarative-gliding-bird

Conversation

@koala73
Copy link
Owner

@koala73 koala73 commented Mar 5, 2026

Summary

After a deploy, users with a cached service worker see 404s on first load because the old SW serves stale HTML referencing old content-hashed bundles. The browser detects the new sw.js and installs it in the background, but the page is already broken.

This adds a controllerchange listener that auto-reloads the page when the new SW takes control. Combined with skipWaiting + clientsClaim, this means: user loads page → old SW serves stale HTML → 404 → new SW installs + activates → controllerchange fires → page auto-reloads → new SW serves fresh HTML → works.

Test plan

  • Deploy, open site with stale SW — should auto-reload within seconds
  • No reload loops (guard with refreshing flag)

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Mar 5, 2026 1:00pm

Request Review

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

When a new SW takes control (after deploy), automatically reload the
page so users get fresh HTML + correct bundle hashes. Prevents the
one-time 404 on first load after deploy where old SW serves stale HTML.
@koala73 koala73 force-pushed the worktree-declarative-gliding-bird branch from c41254e to 2113d9e Compare March 5, 2026 12:58
@koala73 koala73 merged commit 513755b into main Mar 5, 2026
1 of 2 checks passed
aldoyh pushed a commit to aldoyh/worldmonitor that referenced this pull request Mar 6, 2026
When a new SW takes control (after deploy), automatically reload the
page so users get fresh HTML + correct bundle hashes. Prevents the
one-time 404 on first load after deploy where old SW serves stale HTML.
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