fix: deliver session to service worker on first load (authenticated media)#2991
Open
qingyun-wu wants to merge 1 commit into
Open
fix: deliver session to service worker on first load (authenticated media)#2991qingyun-wu wants to merge 1 commit into
qingyun-wu wants to merge 1 commit into
Conversation
…edia) Under authenticated media (MSC3916, mandatory on Synapse >=1.131), images fail with 401 on a fresh load until a second reload. pushSessionToSW only posts the access token when navigator.serviceWorker.controller is set, but on first load the controller is null until the SW claims the page, so the token never reaches the SW before the first media fetches fire. - sw-session: when controller is null, fall back to serviceWorker.ready -> registration.active so the token reaches the SW on first load. - index: re-push the session on 'controllerchange' once the SW takes control. Fixes cinnyapp#2990. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With authenticated media enabled (MSC3916; mandatory on Synapse ≥ 1.131), images/media fail with
401 M_MISSING_TOKENon a fresh load (first visit, hard refresh, incognito) and only work after a second reload.pushSessionToSWposts the access token to the media service worker only whennavigator.serviceWorker.controlleris set. On first load the controller isnulluntil the SW claims the page, so the token never reaches the SW before the first media fetches go out → 401 → broken images.Closes #2990.
Fix
src/sw-session.ts: whencontrolleris null, fall back tonavigator.serviceWorker.ready → registration.activeso the session reaches the SW on first load.src/index.tsx: also re-push the session oncontrollerchange, once the SW takes control.Two tiny changes, using existing patterns; no behavior change once the SW is already controlling the page.
Testing
Verified on a Synapse 1.153 deployment with authenticated media enforced: before, first-load media 401'd until reload; after, media loads on first load (incognito + unregistered-SW tested).
navigator.serviceWorker.controlleris null on that first load, which is the window this fixes.