Repository navigation
fix(mock): version the worker script, so a new build replaces the old one - #1554
Merged
Merged
Conversation
… one The site cache-busts its host files with a version query, and the worker it installs imports runtime-core.js at that stamp. The worker script itself was registered from a constant URL, so a browser that had cached sw.js kept running the previous build's worker - and through it the previous runtime. A site whose runtime gained a capability then handed a fresh drive to an old interpreter: on a published mock site whose runtime now defines webout(), every service that calls it answered "Job execution failed." with "ReferenceError: webout is not defined" until the visitor cleared site data. A private window, or the same build served to a first-time visitor, worked. Registering /sw.js?v=<hostVersion> makes a new build a different script, so the worker installs and its skipWaiting takes over at once; updateViaCache: 'none' keeps a reverse proxy from answering the update check with the previous copy. Verified by building the mocked DC estate with this CLI: the emitted index.html registers /sw.js?v=5277c5d719, the running controller reports that scriptURL, and a POST to services/usernav/usergroupsbymember answers 200 with the groups envelope. The new spec assertion fails if the stamp or updateViaCache is dropped.
Coverage ratchetCompared against the baseline published for the base commit 0f4a06f.
No metric is below the base. |
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.
The mocked site installs a worker from a constant URL, so a browser that had cached
sw.jskept running the previous build's worker - and through it the previous runtime. Both were reproduced on a published mock site today.What it looks like
A site whose runtime had gained the
webout()prelude handed a fresh drive to an old interpreter. Every mock service that callswebout()answered:Opening the same program in a new window - or visiting the same deployment from a profile that had never seen it - worked, because those get the current worker. Clearing the origin's storage fixed it on the spot, which is what pointed at the worker rather than at the build or the service.
The host files are already cache-busted (
?v=<hostVersion>, an md5 overruntime-core.js,persist.js,intercept.js,api-browser.js,webout-prelude.json), and the worker imports its runtime at that stamp - but the worker script itself is registered at/sw.js, so nothing makes the browser look at it again until its own revalidation cadence comes round.The change
A new build is a different script URL, so it installs and its
skipWaiting()takes over immediately;updateViaCache: 'none'stops a reverse proxy from answering the update check with the previous copy. The version is the samehostVersionthe rest of the loader already uses, so the two cannot disagree.Verification
npx jest src/commands/build/internal/mockSite: 190 passing across the five suites; the extended assertion (register('/sw.js?v=,updateViaCache: 'none') fails if either half is dropped.npm run buildclean.index.htmlcarriesregister('/sw.js?v=5277c5d719', { scope: '/', updateViaCache: 'none' }),navigator.serviceWorker.controller.scriptURLis that URL, and a POST toservices/usernav/usergroupsbymemberanswers 200 with the groups envelope.One note for the same class of report:
persist.jsstill skips re-seeding when IndexedDB already holds files, so a stale drive can outlive a stale worker. That is a separate question and I have not touched it here.