Repository navigation
[web] Remove service worker loader and --pwa-strategy - #194785
Conversation
Removes the deprecated `flutter_service_worker.js` self-destructing stub,
the hidden `--pwa-strategy` CLI option, default `serviceWorkerSettings`
bootstrap injection, and `FlutterServiceWorkerLoader` from `flutter.js`.
- `WebTemplate.withSubstitutions` continues replacing
`{{flutter_service_worker_version}}` with `null` and a deprecation
comment (tracked for 2027 H2 removal) so custom `web/flutter_bootstrap.js`
files referencing the placeholder do not fail with a JS `SyntaxError`.
- `WebServiceWorker.build` continues emitting `precache_manifest.json`
when `--web-content-hash` is enabled and writes an empty `service_worker.d`
depfile when disabled so incremental builds do not re-trigger on a
missing depfile.
Fixes flutter#156910
…wa-strategy - Keep emitting the static self-unregistering `build/web/flutter_service_worker.js` stub (unless the project provides a custom `web/flutter_service_worker.js`) and delete legacy `flutter-app-cache`, `flutter-temp-cache`, and `flutter-app-manifest` caches on `activate` so returning browsers upgrading directly from Flutter <= 3.38 cleanly unregister instead of hitting a W3C Service Worker Update 404 trap. - Keep `--pwa-strategy` as a hidden option descriptor and fail with a targeted `throwToolExit` migration message in `flutter build web`.
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If both you and the PR author believe this PR qualifies for a test exemption, escalate to the tech lead for the changed area to review and apply the |
There was a problem hiding this comment.
Code Review
This pull request removes the deprecated offline caching service worker from Flutter Web, deleting the service worker loader, removing the --pwa-strategy build option, and replacing the default service worker with a self-unregistering cleanup stub to purge legacy caches. Feedback on the changes suggests replacing the non-standard null-aware list element syntax (?) with standard collection-if elements in web.dart to ensure compatibility and maintainability.
|
One thing I want to flag about dropping In 3.41–3.47, the loader called With this PR, apps upgrading from Can we keep a minimal version of the active check in if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistration().then((registration) => {
const scriptURL = registration?.active?.scriptURL ?? '';
if (scriptURL.includes('flutter_service_worker.js?v=')) {
navigator.serviceWorker.register(
resolveUrlWithSegments(`flutter_service_worker.js?v=${Date.now()}`),
);
}
});
}
Also, as far as I can tell the soft-update path was only verified on Chrome. The explicit |
…d legacy SW cache-buster
Added
Yes — added |
…vice_worker_test.dart
|
Updated compile_web_test.dart for the 3-argument WebBuilder.buildWeb signature after merging master (34c791d); re-requesting review. |
|
autosubmit label was removed for flutter/flutter/194785, because - This pull request has the |
This was removed in flutter/flutter#194785
Removes
FlutterServiceWorkerLoaderfromflutter.js, removes defaultserviceWorkerSettingsinjection fromflutter_bootstrap.js, and fails--pwa-strategywith a migration error viathrowToolExit.build/web/flutter_service_worker.jsis retained as a static cleanup stub: In Flutter<= 3.38(the last stable series with an activeoffline-firstcaching service worker),flutter_service_worker.jsservesflutter_bootstrap.js,flutter.js, andmain.dart.js100% cache-first fromflutter-app-cache. Returning browsers upgrading directly from a<= 3.38deployment only escapeflutter-app-cachewhen the browser's W3C Service Worker Update check fetches/flutter_service_worker.json navigation. If/flutter_service_worker.jsreturns404 Not Found(or200 text/htmlon SPA hosts), the W3C update check aborts and leaves the<= 3.38worker active indefinitely.WebServiceWorker.buildcontinues emitting the self-unregisteringbuild/web/flutter_service_worker.jsstub (only when the project does not provide a customweb/flutter_service_worker.js), and the stub now also deletes the legacy'flutter-app-manifest','flutter-temp-cache', and'flutter-app-cache'Cache Storage buckets duringactivate.WebTemplate.withSubstitutionslogs a deprecation warning and replaces{{flutter_service_worker_version}}withnull(tracked for 2027 H2 removal) so customweb/flutter_bootstrap.jsorweb/index.htmlfiles referencing the token do not fail with a JSSyntaxError.Fixes #156910
Fixes #136620