Skip to content

Tolerate a missing flutter/service_worker handler in the web first-frame notification - #196329

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
harryterkelsen:propagate-missing-asset-load-errors-on-web
Nov 20, 2026
Merged

auto-submit[bot] merged 7 commits into
flutter:masterfrom
harryterkelsen:propagate-missing-asset-load-errors-on-web

Conversation

@harryterkelsen

Copy link
Copy Markdown
Contributor

On the web, RendererBinding sends a best-effort first-frame message on the flutter/service_worker channel after the first frame. It used a plain MethodChannel, so if nothing handled the channel (a null reply), invokeMethod threw a MissingPluginException, and _handleWebFirstFrame reported that as a FlutterError "while sending the first-frame event".

This PR switches the call to OptionalMethodChannel, the framework's existing class for channels that may have no handler. A missing handler now completes quietly with null. All other failures (for example a PlatformException from an error reply) still go through the unchanged onError block and are reported.

This is groundwork for making the web test environment reply to every platform message the way flutter_tester does on the VM (unhandled channels get a null reply instead of never getting a reply at all). Without this change, that follow-up would make every web test file that draws a frame report this error. In production web the engine never replies on this channel, so production behavior does not change.

Part of #56314

Behavioral Changes

  • Web only. When the flutter/service_worker channel has no handler and the first-frame message gets a null reply:
    • Before: a MissingPluginException (No implementation found for method first-frame on channel flutter/service_worker) was reported through FlutterError.reportError from the rendering library, with context "while sending the first-frame event".
    • After: nothing is reported, and the message completes with null.
  • Any other error from the first-frame call is still reported exactly as before. Nothing changes on non-web platforms, or when a handler replies normally.

Where to focus

  • Primary review file: packages/flutter/lib/src/rendering/binding.dart, _handleWebFirstFrame. The fix swaps one class name. The only difference OptionalMethodChannel makes is missingOk: true in _invokeMethod, so error reporting for every other failure stays the same.
  • Test design: packages/flutter/test/rendering/first_frame_missing_handler_test.dart is a new web-only file with its own TestRenderBinding, the same as first_frame_test.dart. It can't live in that file because the first-frame post-frame callback fires once per binding, so each scenario needs a fresh binding (one per file). The first test must run before any other test in the file draws a frame. A comment in the file says so.
  • Why a raw binary mock: the test uses setMockMessageHandler returning null, not setMockMethodCallHandler. A method-call handler that returns null sends back a success envelope, so the test would never exercise the missing-handler path.
  • The second test checks that later frames don't send the notification again. That one-shot behavior had no test before.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 10, 2026
@harryterkelsen harryterkelsen added platform-web Web applications specifically team-web Owned by Web platform team a: tests "flutter test", flutter_test, or one of our tests labels Nov 10, 2026
@harryterkelsen
harryterkelsen marked this pull request as ready for review November 10, 2026 22:30
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Nov 10, 2026

@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 updates RendererBinding._handleWebFirstFrame to use an OptionalMethodChannel for the flutter/service_worker channel, ensuring that a missing handler does not trigger an error on the web. It also introduces a new test file to verify this behavior. The reviewer recommends combining the two newly added tests into a single test to avoid issues with shared state in the TestRenderBinding instance, which currently prevents the second test from starting with a clean binding state.

@github-actions github-actions Bot removed a: tests "flutter test", flutter_test, or one of our tests platform-web Web applications specifically team-web Owned by Web platform team labels Nov 10, 2026
@harryterkelsen harryterkelsen added the team-web Owned by Web platform team label Nov 17, 2026
@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 20, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 20, 2026
Merged via the queue into flutter:master with commit 4bdaa46 Nov 20, 2026
24 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 20, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 21, 2026
flutter/flutter@b34b017...5423f94

2026-11-21 [email protected] Make an Impeller render target from a Vulkan backing store (flutter/flutter#193003)
2026-11-21 [email protected] Persist the vulkan shader cache on teardown (flutter/flutter#197017)
2026-11-21 [email protected] [flutter_tools] Preserve rolling log buffer for Chromium crash diagnostics (flutter/flutter#196037)
2026-11-21 [email protected] Roll Skia from 8845aecd8c53 to 39e0ad394168 (2 revisions) (flutter/flutter#197094)
2026-11-21 [email protected] Adds redirect for listen package in api.flutter.dev (flutter/flutter#197068)
2026-11-21 [email protected] Roll Dart SDK from c6857d58f0ec to fc86f5a42779 (1 revision) (flutter/flutter#197086)
2026-11-20 [email protected] iOS: Discard pending platform view disposals on reset (flutter/flutter#197026)
2026-11-20 [email protected] Tolerate a missing flutter/service_worker handler in the web first-frame notification (flutter/flutter#196329)
2026-11-20 [email protected] Roll Skia from 9aafbb357743 to 8845aecd8c53 (2 revisions) (flutter/flutter#197080)
2026-11-20 [email protected] Prevent crash in tessellator with extreme radii (flutter/flutter#196648)
2026-11-20 [email protected] Windows: in the flutter tool, always close the file handle in _download even when an HTTP request fails so that it is not left open and becomes undeletable (flutter/flutter#197061)
2026-11-20 [email protected] Roll Skia from b61640825c5b to 9aafbb357743 (7 revisions) (flutter/flutter#197066)
2026-11-20 [email protected] Swap dependabot reviewers (flutter/flutter#196995)
2026-11-20 [email protected] [iOS] Hide UIScrollEdgeEffect on FlutterSemanticsScrollView and scroll-to-top UIScrollView on iOS 26+ (flutter/flutter#195356)
2026-11-20 [email protected] [devicelab] Enable Vulkan GPU tracing by default on Android Impeller PerfTests (flutter/flutter#196822)
2026-11-20 [email protected] Roll Dart SDK from 3b5f45d812f8 to c6857d58f0ec (1 revision) (flutter/flutter#197063)
2026-11-20 [email protected] [flutter_tools] Delete flutter.version.json when switching channels (flutter/flutter#196943)
2026-11-20 [email protected] Update desktop TESTOWNERS (flutter/flutter#196930)
2026-11-20 [email protected] [web] Release CanvasKit WebGL contexts and surfaces when a view is removed (flutter/flutter#196816)
2026-11-20 [email protected] [Linux] Hide libunwind symbols in libflutter_linux_gtk.so (flutter/flutter#196451)
2026-11-20 [email protected] Roll Skia from a1edf5c2ea5c to b61640825c5b (1 revision) (flutter/flutter#197058)
2026-11-20 [email protected] [flutter_tools] Update --web-content-hash serving tip to cover assets and canvaskit (flutter/flutter#196908)
2026-11-20 [email protected] Send a semantics update when only the identifier changes (flutter/flutter#196460)
2026-11-20 [email protected] Roll Packages from 81b7c44 to 898818d (11 revisions) (flutter/flutter#197056)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode 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
bkonyi pushed a commit to bkonyi/flutter that referenced this pull request Nov 25, 2026
… missing-asset tests (flutter#197267)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

Make the web engine's `flutter_tester` emulation
(`ui_web.TestEnvironment.ignorePlatformMessages`) reply `null`
asynchronously to outgoing platform messages instead of dropping their
response callbacks, and unskip the missing-asset framework tests on web.

Previously, when running `flutter test --platform chrome`
(`TestEnvironment.flutterTester()`),
`EnginePlatformDispatcher._sendPlatformMessage` returned early without
ever invoking `callback`. Any caller awaiting an unmocked platform
channel—such as `rootBundle.load` or `ExactAssetImage` loading a
nonexistent asset—hung until the 30-second test timeout instead of
receiving the standard empty (`null`) unhandled-channel reply that
native `flutter_tester` and production web 404 responses return. With
flutter#196329 switching `RendererBinding._handleWebFirstFrame`
(`flutter/service_worker`) to `OptionalMethodChannel`, replying `null`
uniformly across all channels in `ignorePlatformMessages` mode aligns
web tests with native `flutter_tester` without triggering spurious
`MissingPluginException` errors.

Fixes flutter#56314

Also updates the skip rationale comment on `Failed image loads in debug
mode` in `packages/flutter/test/widgets/image_test.dart` (tracked in
flutter#74935) to document that
`Image.asset` still requires `AssetManifest.bin.json`, which web unit
tests do not currently serve.

## Behavioral Changes

- **Before**: When `ui_web.TestEnvironment.ignorePlatformMessages` is
`true` (including `TestEnvironment.flutterTester()` under `flutter test
--platform chrome`), `EnginePlatformDispatcher.sendPlatformMessage`
drops outgoing messages without invoking `callback`. Unmocked platform
channel calls (such as `rootBundle.load` or `AssetBundleImageProvider`
for a missing asset) never complete and hang until test timeout, leaving
pending futures in `TestDefaultBinaryMessenger` and pending entries in
`ImageCache`.
- **After**: When `ui_web.TestEnvironment.ignorePlatformMessages` is
`true`, `EnginePlatformDispatcher.sendPlatformMessage` still skips
engine channel handlers, but schedules `callback(null)` asynchronously
via a zero-duration timer on `Zone.root`. Unhandled channels receive an
empty (`null`) reply on a subsequent event-loop turn (executed in the
caller's registration zone), causing missing-asset loads in web tests to
throw `FlutterError('Unable to load asset: ...')` and evict pending
`ImageCache` entries just as on the VM. Production web apps
(`ignorePlatformMessages == false`, and profile/release builds where
`assert` blocks are stripped) are unaffected.

## Where to focus

- **Key Architectural Decisions**:
`EnginePlatformDispatcher._sendPlatformMessage` replies `null` uniformly
to every channel when `ignorePlatformMessages` is enabled rather than
special-casing `flutter/assets`. This matches native `flutter_tester`
semantics for unhandled channels across the board now that
`RendererBinding._handleWebFirstFrame` uses `OptionalMethodChannel`
(flutter#196329).
- **Non-Obvious Logic**: The `null` reply is scheduled with
`Zone.root.createTimer(Duration.zero, () => callback(null))` rather than
synchronously or via `replyToPlatformMessage`. Synchronous replies
violate callers' async expectations, while `replyToPlatformMessage` uses
`Future<void>.delayed(Duration.zero)` in `Zone.current`, which registers
a `FakeAsync` timer inside `testWidgets` and fails end-of-test timer
invariants when widgets send platform messages without a subsequent
`pump()`. Because `sendPlatformMessage` wraps `callback` in
`_zonedPlatformMessageResponseCallback`, scheduling on `Zone.root`
avoids `FakeAsync` timers while still running the callback in its
registration zone.
- **Primary Review Files**:
-
`engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart`
— asynchronous root-zone `null` reply in `_sendPlatformMessage` when
`ignorePlatformMessages` is true.
- `engine/src/flutter/lib/web_ui/lib/ui_web/src/ui_web/testing.dart` —
updated `TestEnvironment.ignorePlatformMessages` doc comment.
-
`engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher/platform_dispatcher_test.dart`
— unit tests covering async delivery, skipped asset fetches,
registration zone preservation, `FakeAsync` timer isolation, `tearDown`
transitions, and FIFO ordering.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels. team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants