Skip to content

fix: resolve stale cache on GitHub Pages deploys#25

Merged
nsheaps merged 2 commits intomainfrom
claude/fix-github-pages-cache-DmbWv
Mar 9, 2026
Merged

fix: resolve stale cache on GitHub Pages deploys#25
nsheaps merged 2 commits intomainfrom
claude/fix-github-pages-cache-DmbWv

Conversation

@nsheaps
Copy link
Copy Markdown
Owner

@nsheaps nsheaps commented Mar 8, 2026

Summary

  • Registers the service worker that was previously built but never wired into the app, enabling proper cache management and offline support
  • Auto-activates new service worker versions on page load so users always see the latest content without needing a hard refresh
  • Shows a toast notification ("App updated to vX.Y.Z") after the page reloads with a new version, auto-dismissing after 6 seconds

How it works

  1. On page load, the app registers service-worker.js and listens for new versions
  2. When a new SW is detected (waiting to activate), it immediately sends SKIP_WAITING
  3. On controllerchange, a sessionStorage flag is set and the page reloads
  4. After reload, the flag is consumed and the UpdateToast component displays the version

Changes

  • service-worker.ts: Removed auto skipWaiting() from install handler (client now controls activation timing)
  • sw-register.ts: Added controllerchange listener, auto-update flow, and consumeUpdateFlag() helper
  • main.tsx: Registers the service worker on mount, renders UpdateToast after updates
  • vite.config.ts: Builds service-worker.ts as a separate Rollup entry at a fixed path (service-worker.js)
  • UpdateToast.tsx: New toast component with enter/exit animations and auto-dismiss

Test plan

  • service-worker.test.ts — 6 tests pass
  • sw-register.test.ts — 5 tests pass
  • UpdateToast.test.tsx — 5 tests pass
  • TypeScript strict mode — no errors
  • Production build succeeds
  • Manual: Deploy to GitHub Pages, verify auto-reload and toast

https://claude.ai/code/session_012PcsftUoC8NyeLLV9LD3rE

Wire up the existing service worker registration so the app detects new
versions deployed to GitHub Pages. When a new service worker is found,
it automatically activates and reloads the page. After reload, a toast
notification shows "App updated to vX.Y.Z".

Key changes:
- Remove auto-skipWaiting from SW install (client controls activation)
- Register SW in main.tsx with the correct base URL
- Add controllerchange listener to auto-reload on SW activation
- Create UpdateToast component with auto-dismiss after 6s
- Build service-worker.ts as a separate Rollup entry at a fixed path
- Add tests for consumeUpdateFlag, UpdateToast, and SW exports

https://claude.ai/code/session_012PcsftUoC8NyeLLV9LD3rE
@nsheaps nsheaps self-assigned this Mar 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

Release Version Check

🟡 MINOR version bump

Version
Current 0.1.0
Next 0.2.0

This version will be released automatically when this PR is merged to main.

Changelog preview

0.2.0 (2026-03-08)

Features

  • toggle syntax, UI fixes, demos, screenshots & CI (#22) (2f0b8ed)

Bug Fixes

  • register service worker and auto-update on new deploys (34e8129)

Documentation

  • screenshots: update feature screenshots (353dfd4)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 8, 2026

Preview Deployment

The web app for this PR has been deployed:

Open Preview

Use this to verify the app works correctly, especially for dependency updates.

github-actions bot added a commit that referenced this pull request Mar 8, 2026
github-actions bot added a commit that referenced this pull request Mar 8, 2026
@nsheaps nsheaps marked this pull request as ready for review March 9, 2026 04:02
@nsheaps nsheaps merged commit 024e146 into main Mar 9, 2026
10 checks passed
@nsheaps nsheaps deleted the claude/fix-github-pages-cache-DmbWv branch March 9, 2026 04:02
github-actions bot added a commit that referenced this pull request Mar 9, 2026
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.

2 participants