Skip to content

fix: handle service worker registration edge cases#960

Draft
lidel wants to merge 4 commits intomainfrom
fix/service-worker-registration
Draft

fix: handle service worker registration edge cases#960
lidel wants to merge 4 commits intomainfrom
fix/service-worker-registration

Conversation

@lidel
Copy link
Member

@lidel lidel commented Jan 21, 2026

this PR is belt and suspenders protection against edge cases that could leave users stuck on loading screen.

i've seen crazy bugs in Google Chrome shipping in production, and then they silently fixed them month later, wasting peoples time on debug

these should not impact normal operation, but will save debugging time if we ever hit them thanks to clear error messages and timeout

belt and suspenders protection against edge cases that could leave users
stuck on loading screen. these should not impact normal operation, but
will save debugging time if we ever hit them thanks to clear error
messages and timeout:

1. race condition: only listened for `updatefound`, but if a worker was
   already installing or waiting, we'd miss it and wait forever

2. no timeout: if worker failed to activate, the promise would never
   resolve and page would hang indefinitely

3. silent failures: if worker became redundant (replaced by newer
   version mid-install), we had no handling and would wait forever

now we track existing installing/waiting workers, add a 30s timeout, and
properly reject if worker becomes redundant.
@lidel lidel requested a review from achingbrain January 21, 2026 15:57
@lidel lidel force-pushed the fix/service-worker-registration branch from 46ef88f to b847d05 Compare January 21, 2026 16:06
refactor to use idempotent succeed/fail helpers that prevent double
resolution. check worker state after adding listener to close race
condition window where worker could activate before listener attached.
@lidel lidel force-pushed the fix/service-worker-registration branch from b847d05 to 2d86369 Compare January 21, 2026 16:11
@achingbrain
Copy link
Member

Is it possible to add some tests here? I'm not sure I'd want to refactor this without having some assurance a refactor would not break something.

lidel added 2 commits January 21, 2026 22:00
an attempt at E2E tests for SW registration, but these are closer to
unit tests than true E2E - they test the registration mechanism in
isolation rather than user-facing behavior.

may not be worth keeping, but provides some regression coverage for:
- fresh registration activation
- re-registration after unregister
- multiple register/unregister cycles

note: timeout error page cannot be tested due to Playwright limitation
(SW script fetches are not interceptable)
@lidel
Copy link
Member Author

lidel commented Jan 22, 2026

@achingbrain unsure how we can test this fully, i looked at playwright docs and it cant intercept the SW registration requests in a way that allows us to test it E2E.

Added two other tests but they don't project as much confidence as proper e2e would.

We probably can park/close this PR and revisit if we ever see actual bugs irl. I agree we dont want to change this unless we need too.

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