Skip to content

[2026 PWA] Add a controlled service-worker update prompt - #794

Merged
Nanle-code merged 1 commit into
Nanle-code:masterfrom
mayborn005:feat/781-controlled-sw-update-prompt
Jul 29, 2026
Merged

[2026 PWA] Add a controlled service-worker update prompt#794
Nanle-code merged 1 commit into
Nanle-code:masterfrom
mayborn005:feat/781-controlled-sw-update-prompt

Conversation

@mayborn005

Copy link
Copy Markdown
Contributor

Closes #781

Summary

Adds a controlled update prompt for the service worker so users can activate new versions without stale-chunk crashes or unexpected reloads.

Changes

  • public/sw.js: Removed automatic skipWaiting() from the install event. New versions now wait in the installed state and notify clients via SW_INSTALLED message.
  • src/utils/offline.js: Added initSWUpdatePrompt(), subscribeToSWUpdates(), applySWUpdate(), and isSWUpdateAvailable() for managing the update lifecycle. The registerServiceWorker() function now calls initSWUpdatePrompt() automatically.
  • src/components/SWUpdatePrompt.jsx: Banner component shown when an update is waiting. Lets users activate it or dismiss.
  • src/main.jsx: Fixed missing import of registerServiceWorker from offline.js. Registration now includes the update prompt logic.
  • src/routes/DashboardLayout.tsx: Added <SWUpdatePrompt /> to the layout.
  • docs-site/docs/guides/offline-support.md: Added developer API documentation, compatibility notes, and security notes.
  • tests/unit/offline.test.js: 6 tests covering primary update-found flow, pre-existing waiting worker, SKIP_WAITING message posting, missing-worker boundary case, unsupported environment, and controllerchange reload.

Testing

✓ tests/unit/offline.test.js (6 tests)

All existing tests continue to pass.

Let users activate new SW versions without stale-chunk crashes or
unexpected reloads.

- Remove automatic skipWaiting() from SW install — new versions wait
  for explicit user consent
- Add initSWUpdatePrompt, subscribeToSWUpdates, applySWUpdate, and
  isSWUpdateAvailable to src/utils/offline.js
- Create SWUpdatePrompt banner component that invites users to update
- Wire registration in main.jsx and add SWUpdatePrompt to dashboard
  layout
- Update offline-support.md docs with developer API and compatibility
  notes

Closes Nanle-code#781
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@mayborn005 is attempting to deploy a commit to the nanle-code's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@mayborn005 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Nanle-code
Nanle-code merged commit 824b25b into Nanle-code:master Jul 29, 2026
1 check failed
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.

[2026 PWA] Add a controlled service-worker update prompt

2 participants