Skip to content

[web] Self-cleaning service worker - #176834

Merged
auto-submit[bot] merged 20 commits into
flutter:masterfrom
mdebbar:self_cleaning_sw
Oct 17, 2025
Merged

auto-submit[bot] merged 20 commits into
flutter:masterfrom
mdebbar:self_cleaning_sw

Conversation

@mdebbar

@mdebbar mdebbar commented Oct 10, 2025 •

Copy link
Copy Markdown
Contributor

Introduce a self-cleaning service worker to replace the old one.

Previous attempts (#170918, #173609) had (accidentally?) disabled the loading of the service worker in flutter.js. This PR preserves the logic for loading the service worker, and it prints a deprecation warning.

Towards #156910
Closes #106225

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels Oct 10, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a self-cleaning service worker to replace the previous caching service worker, which is a significant and positive simplification. The changes are extensive, affecting the Flutter tool, flutter.js, and various test files. The new service worker's role is to unregister itself and reload clients, effectively removing the old caching behavior. The logic in flutter.js is cleverly updated to only register this new worker if an old one is detected, ensuring a smooth transition for existing applications while not affecting new ones. The test suite has been appropriately refactored with a new integration test that validates this cleanup mechanism. The implementation is solid, but I have one suggestion to improve the robustness of the test code.

Comment thread dev/bots/service_worker_test.dart Outdated
@mdebbar
mdebbar requested a review from jtmcdole as a code owner October 14, 2025 15:21
@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages p: cupertino_ui cupertino_ui package in flutter/packages labels Oct 14, 2025
@github-actions github-actions Bot removed framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages p: cupertino_ui cupertino_ui package in flutter/packages labels Oct 14, 2025
@auto-submit

auto-submit Bot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/176834, because - The status or check suite Linux gradle_plugin_light_apk_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 16, 2025
@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 16, 2025
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 16, 2025
@auto-submit

auto-submit Bot commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/176834, because - The status or check suite Linux linux_fuchsia_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 17, 2025
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 17, 2025
Merged via the queue into flutter:master with commit f94a942 Oct 17, 2025
183 of 184 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 17, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 18, 2025
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Oct 18, 2025
Roll Flutter from a873a27 to 891d7d5 (32 revisions)

flutter/flutter@a873a27...891d7d5

2025-10-18 [email protected] Roll Skia from b4981b621a54 to 74df18176924 (1 revision) (flutter/flutter#177204)
2025-10-18 [email protected] Roll Fuchsia Linux SDK from ZHuhfPyyV-LcKDLRh... to M8WT2GMY46e_0fFho... (flutter/flutter#177200)
2025-10-18 [email protected] [material/dropdown_menu.dart] Refactor  _RenderDropdownMenuBody.computeDryLayout  (flutter/flutter#176503)
2025-10-18 [email protected] Roll Skia from 579c72d673dd to b4981b621a54 (2 revisions) (flutter/flutter#177199)
2025-10-17 [email protected] Roll Skia from 89a8bc508a7c to 579c72d673dd (15 revisions) (flutter/flutter#177194)
2025-10-17 [email protected] [test_fixes] Enable `deprecated_member_use_from_same_package`. (flutter/flutter#177183)
2025-10-17 [email protected] [a11y] fix table semantics cache for cells  (flutter/flutter#177073)
2025-10-17 [email protected] [web] Self-cleaning service worker (flutter/flutter#176834)
2025-10-17 [email protected] Manual roll Skia from 2d9df7c70b6f to 89a8bc508a7c (24 revisions) (flutter/flutter#177182)
2025-10-17 [email protected] Fixing WindowManagerTest::DialogCanNeverBeFullscreen possibly hanging (flutter/flutter#177179)
2025-10-17 [email protected] [VPAT][A11y][a11y-app] Add a text label to slider.  (flutter/flutter#177130)
2025-10-17 [email protected] Manual roll Dart SDK from a4485e5ef821 to a66f334fee2a (5 revisions) (flutter/flutter#177142)
2025-10-17 [email protected] [web][a11y] Fix the semantics tree reconstruction logic when a subtree is reparented to another node.  (flutter/flutter#177069)
2025-10-17 [email protected] `SelectableRegion` should use flutter rendered menu on the web for Android and iOS (flutter/flutter#177122)
2025-10-17 [email protected] Refactor: Convert Title widget to StatefulWidget (flutter/flutter#176010)
2025-10-17 [email protected] Bump AGP, KGP, Gradle Templates (flutter/flutter#176858)
2025-10-17 [email protected] Roll Packages from 835dccb to 3747006 (3 revisions) (flutter/flutter#177170)
2025-10-17 [email protected] Mark windows_unopt test as flakey (flutter/flutter#177173)
2025-10-17 [email protected] Tapping outside of `SelectableRegion` should dismiss the selection (flutter/flutter#176843)
2025-10-17 [email protected] Roll Fuchsia Linux SDK from _dd0Jv50H0oUI2Ad8... to ZHuhfPyyV-LcKDLRh... (flutter/flutter#177137)
2025-10-17 [email protected] Manual roll Dart to a4485e5ef821 (3.11.0-25.0.dev) (flutter/flutter#177132)
2025-10-17 [email protected] Make sure that a MenuAcceleratorLabel doesn't crash in 0x0 environment (flutter/flutter#176646)
2025-10-16 [email protected] Make sure that a NavigationRail doesn't crash in 0x0 environment (flutter/flutter#177022)
2025-10-16 [email protected] Make sure that a SubmenuButton doesn't crash in 0x0 environment (flutter/flutter#176535)
2025-10-16 [email protected] Fix typo in ButtonBar documentation (flutter/flutter#177078)
2025-10-16 [email protected] Make sure that an InkResponse doesn't crash in 0x0 environment (flutter/flutter#175426)
2025-10-16 [email protected] [Gradle 9] Resolve Gradle 9 Deprecations in flutter/flutter part 1 (flutter/flutter#176865)
2025-10-16 [email protected] Revert "Resolve resolve native Flutter dependencies in Android Studio (#167332)" (flutter/flutter#177053)
2025-10-16 [email protected] Manual roll Dart SDK from 2d8e0359a767 to 25b6094026e4 (5 revisions) (flutter/flutter#177109)
2025-10-16 [email protected] Add textfield prop to SearchAnchor (flutter/flutter#174497)
2025-10-16 [email protected] Fix crash when NSAttributedString is passed to insertText on macOS (flutter/flutter#176329)
2025-10-16 [email protected] Correct basque time format (flutter/flutter#177031)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
...
@mdebbar
mdebbar deleted the self_cleaning_sw branch October 20, 2025 17:11
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
Introduce a self-cleaning service worker to replace the old one.

Previous attempts (flutter#170918,
flutter#173609) had (accidentally?)
disabled the loading of the service worker in `flutter.js`. This PR
preserves the logic for loading the service worker, and it prints a
deprecation warning.

Towards flutter#156910
Closes flutter#106225
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2026
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
Roll Flutter from a873a27 to 891d7d5 (32 revisions)

flutter/flutter@a873a27...891d7d5

2025-10-18 [email protected] Roll Skia from b4981b621a54 to 74df18176924 (1 revision) (flutter/flutter#177204)
2025-10-18 [email protected] Roll Fuchsia Linux SDK from ZHuhfPyyV-LcKDLRh... to M8WT2GMY46e_0fFho... (flutter/flutter#177200)
2025-10-18 [email protected] [material/dropdown_menu.dart] Refactor  _RenderDropdownMenuBody.computeDryLayout  (flutter/flutter#176503)
2025-10-18 [email protected] Roll Skia from 579c72d673dd to b4981b621a54 (2 revisions) (flutter/flutter#177199)
2025-10-17 [email protected] Roll Skia from 89a8bc508a7c to 579c72d673dd (15 revisions) (flutter/flutter#177194)
2025-10-17 [email protected] [test_fixes] Enable `deprecated_member_use_from_same_package`. (flutter/flutter#177183)
2025-10-17 [email protected] [a11y] fix table semantics cache for cells  (flutter/flutter#177073)
2025-10-17 [email protected] [web] Self-cleaning service worker (flutter/flutter#176834)
2025-10-17 [email protected] Manual roll Skia from 2d9df7c70b6f to 89a8bc508a7c (24 revisions) (flutter/flutter#177182)
2025-10-17 [email protected] Fixing WindowManagerTest::DialogCanNeverBeFullscreen possibly hanging (flutter/flutter#177179)
2025-10-17 [email protected] [VPAT][A11y][a11y-app] Add a text label to slider.  (flutter/flutter#177130)
2025-10-17 [email protected] Manual roll Dart SDK from a4485e5ef821 to a66f334fee2a (5 revisions) (flutter/flutter#177142)
2025-10-17 [email protected] [web][a11y] Fix the semantics tree reconstruction logic when a subtree is reparented to another node.  (flutter/flutter#177069)
2025-10-17 [email protected] `SelectableRegion` should use flutter rendered menu on the web for Android and iOS (flutter/flutter#177122)
2025-10-17 [email protected] Refactor: Convert Title widget to StatefulWidget (flutter/flutter#176010)
2025-10-17 [email protected] Bump AGP, KGP, Gradle Templates (flutter/flutter#176858)
2025-10-17 [email protected] Roll Packages from 835dccb to 3747006 (3 revisions) (flutter/flutter#177170)
2025-10-17 [email protected] Mark windows_unopt test as flakey (flutter/flutter#177173)
2025-10-17 [email protected] Tapping outside of `SelectableRegion` should dismiss the selection (flutter/flutter#176843)
2025-10-17 [email protected] Roll Fuchsia Linux SDK from _dd0Jv50H0oUI2Ad8... to ZHuhfPyyV-LcKDLRh... (flutter/flutter#177137)
2025-10-17 [email protected] Manual roll Dart to a4485e5ef821 (3.11.0-25.0.dev) (flutter/flutter#177132)
2025-10-17 [email protected] Make sure that a MenuAcceleratorLabel doesn't crash in 0x0 environment (flutter/flutter#176646)
2025-10-16 [email protected] Make sure that a NavigationRail doesn't crash in 0x0 environment (flutter/flutter#177022)
2025-10-16 [email protected] Make sure that a SubmenuButton doesn't crash in 0x0 environment (flutter/flutter#176535)
2025-10-16 [email protected] Fix typo in ButtonBar documentation (flutter/flutter#177078)
2025-10-16 [email protected] Make sure that an InkResponse doesn't crash in 0x0 environment (flutter/flutter#175426)
2025-10-16 [email protected] [Gradle 9] Resolve Gradle 9 Deprecations in flutter/flutter part 1 (flutter/flutter#176865)
2025-10-16 [email protected] Revert "Resolve resolve native Flutter dependencies in Android Studio (#167332)" (flutter/flutter#177053)
2025-10-16 [email protected] Manual roll Dart SDK from 2d8e0359a767 to 25b6094026e4 (5 revisions) (flutter/flutter#177109)
2025-10-16 [email protected] Add textfield prop to SearchAnchor (flutter/flutter#174497)
2025-10-16 [email protected] Fix crash when NSAttributedString is passed to insertText on macOS (flutter/flutter#176329)
2025-10-16 [email protected] Correct basque time format (flutter/flutter#177031)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
...
Crash-- added a commit to linagora/twake-on-matrix that referenced this pull request Aug 28, 2026
Flutter does not content-hash its build output, so nginx has to send
`Cache-Control: no-cache` for it: every asset is revalidated on each
load. Measured on a warm reload, 56 of 56 requests were conditional and
none was served without a round trip, for 17 KB of actual payload.

The invalidation mechanism this build needs is a path/MD5 manifest
diffed between deploys. Flutter used to ship exactly that as
flutter_service_worker.js and replaced it with a self-unregistering stub
in 3.39 (flutter/flutter#176834), so the logic moves into
web/push_sw.js, whose manifest is generated at build time. Push and
precache share one file because a scope can only be controlled by a
single worker.

index.html stops unregistering service workers on load and registers
this one instead, awaiting it so a first install does not download
main.dart.js twice.

config.json is deliberately excluded from the manifest: it is injected
at deploy time from Helm values, so a build-time hash would pin the app
to a stale homeserver or VAPID key.
Crash-- added a commit to linagora/twake-on-matrix that referenced this pull request Aug 28, 2026
Flutter does not content-hash its build output, so nginx has to send
`Cache-Control: no-cache` for it: every asset is revalidated on each
load. Measured on a warm reload, 56 of 56 requests were conditional and
none was served without a round trip, for 17 KB of actual payload.

The invalidation mechanism this build needs is a path/MD5 manifest
diffed between deploys. Flutter used to ship exactly that as
flutter_service_worker.js and replaced it with a self-unregistering stub
in 3.39 (flutter/flutter#176834), so the logic moves into
web/push_sw.js, whose manifest is generated at build time. Push and
precache share one file because a scope can only be controlled by a
single worker.

index.html stops unregistering service workers on load and registers
this one instead, awaiting it so a first install does not download
main.dart.js twice.

config.json is deliberately excluded from the manifest: it is injected
at deploy time from Helm values, so a build-time hash would pin the app
to a stale homeserver or VAPID key.
Crash-- added a commit to linagora/twake-on-matrix that referenced this pull request Aug 28, 2026
Flutter does not content-hash its build output, so nginx has to send
`Cache-Control: no-cache` for it: every asset is revalidated on each
load. Measured on a warm reload, 56 of 56 requests were conditional and
none was served without a round trip, for 17 KB of actual payload.

The invalidation mechanism this build needs is a path/MD5 manifest
diffed between deploys. Flutter used to ship exactly that as
flutter_service_worker.js and replaced it with a self-unregistering stub
in 3.39 (flutter/flutter#176834), so the logic moves into
web/push_sw.js, whose manifest is generated at build time. Push and
precache share one file because a scope can only be controlled by a
single worker.

index.html stops unregistering service workers on load and registers
this one instead, awaiting it so a first install does not download
main.dart.js twice.

config.json is deliberately excluded from the manifest: it is injected
at deploy time from Helm values, so a build-time hash would pin the app
to a stale homeserver or VAPID key.
Crash-- added a commit to linagora/twake-on-matrix that referenced this pull request Aug 29, 2026
Flutter does not content-hash its build output, so nginx has to send
`Cache-Control: no-cache` for it: every asset is revalidated on each
load. Measured on a warm reload, 56 of 56 requests were conditional and
none was served without a round trip, for 17 KB of actual payload.

The invalidation mechanism this build needs is a path/MD5 manifest
diffed between deploys. Flutter used to ship exactly that as
flutter_service_worker.js and replaced it with a self-unregistering stub
in 3.39 (flutter/flutter#176834), so the logic moves into
web/push_sw.js, whose manifest is generated at build time. Push and
precache share one file because a scope can only be controlled by a
single worker.

index.html stops unregistering service workers on load and registers
this one instead, awaiting it so a first install does not download
main.dart.js twice.

config.json is deliberately excluded from the manifest: it is injected
at deploy time from Helm values, so a build-time hash would pin the app
to a stale homeserver or VAPID key.
9clg6 pushed a commit to linagora/twake-on-matrix that referenced this pull request Sep 17, 2026
* fix(web): serve build assets from a precache service worker

Flutter does not content-hash its build output, so nginx has to send
`Cache-Control: no-cache` for it: every asset is revalidated on each
load. Measured on a warm reload, 56 of 56 requests were conditional and
none was served without a round trip, for 17 KB of actual payload.

The invalidation mechanism this build needs is a path/MD5 manifest
diffed between deploys. Flutter used to ship exactly that as
flutter_service_worker.js and replaced it with a self-unregistering stub
in 3.39 (flutter/flutter#176834), so the logic moves into
web/push_sw.js, whose manifest is generated at build time. Push and
precache share one file because a scope can only be controlled by a
single worker.

index.html stops unregistering service workers on load and registers
this one instead, awaiting it so a first install does not download
main.dart.js twice.

config.json is deliberately excluded from the manifest: it is injected
at deploy time from Helm values, so a build-time hash would pin the app
to a stale homeserver or VAPID key.

* fix(web): keep failed responses out of the shell cache

onlineFirst cached whatever the network returned for a root navigation,
including error pages. A 500 served during a deploy would have been
stored as the shell and then handed back by the offline fallback, so the
app would start into that error page until the next successful load
replaced it.

The response still reaches the page; it just no longer enters the cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-web Web applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Improve dev/bots/service_worker_test

2 participants