Repository navigation
Switch to the new worker first when a deploy changes the engine - #28
Closed
mike-doctorina wants to merge 1 commit into
Closed
mike-doctorina wants to merge 1 commit into
mike-doctorina wants to merge 1 commit into
Conversation
On the first load after a deploy the previous worker still controls the page and serves its cached main.dart.*, while index.html and bootstrap.js are the new build's and the bootstrap loads the engine for the new revision. On the same engine that mix runs; after a Flutter upgrade it fails inside the engine. The worker now reports its build's engineRevision on getVersion. The bootstrap asks the controller for it: - Same engine: boot with the controller at once, without the 4s activation wait it spent for nothing; the new worker takes over on the next load. - Different or unknown engine (earlier workers don't report it): wait for the new worker to install, hand control to it before any app file is requested, and reload once if the handover is lost. A failed install leaves the page on its controller, as before.
This was referenced Oct 29, 2026
Collaborator
Author
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.
Stacked on #27, merge after it.
Problem
On the first load after a deploy, the previous build's worker still controls the page:
main.dart.*cache-first;index.html(network-first) andbootstrap.js(never intercepted) are already the new build's;engineRevision.On the same engine that mix runs, because
flutter.jsand the engine only change together with the Flutter SDK. After a Flutter upgrade it fails inside the engine (WebAssembly.instantiate(): Import #N). On a live deployment the same first load also waited out the full 4 s activation timeout before CanvasKit started.Fix
engineRevisionin thegetVersionreply. The generator writes it into thesw.jsconfig, and only when the build has one.settleUpdateAtBootstrap, runs after registration and outside the 10 s registration cap):registerAndActivateno longer waits 4 s for a worker that cannot activate while the page is open.SW_UPDATE_INSTALL_TIMEOUT_MS) for the new worker to install. The precache progress is on screen through the existingsw-progresscounter.sessionStorageguard against loops.Verification
e2e/engine-update.spec.ts, new): deploys the example twice over a local host, with a marker inmain.dart.js.settleUpdateAtBootstrapremoved it runs the old one (Expected "b", Received "a").--repeat-each=5. The full suite passed, 19/19, run locally on installed Chrome.settleUpdateAtBootstraptests fail against a stub.analyze,formatandnpm run verifyare clean.Overlap with #25
This includes #25's first-load change: a controlled page no longer waits for a pending worker. It does not include #25's shorter 500 ms handover bound. When #25 is rebased, its
registerAndActivatepart reduces to the handover timeout.