Skip to content

fix(web): handle asynchronously disposed platform views#183666

Merged
auto-submit[bot] merged 8 commits intoflutter:masterfrom
harryterkelsen:fix-async-frame-render-issues
Mar 18, 2026
Merged

fix(web): handle asynchronously disposed platform views#183666
auto-submit[bot] merged 8 commits intoflutter:masterfrom
harryterkelsen:fix-async-frame-render-issues

Conversation

@harryterkelsen
Copy link
Contributor

@harryterkelsen harryterkelsen commented Mar 13, 2026

Check if platform views still exist in PlatformViewManager before compositing to avoid crashes if they are disposed during async gaps in the rendering pipeline.

Added test/ui/async_rendering_test.dart.

Fixes #182844
Fixes #176299

Pre-launch Checklist

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

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 engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels Mar 13, 2026
@harryterkelsen harryterkelsen requested a review from mdebbar March 13, 2026 21:56
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Mar 13, 2026
Copy link
Contributor

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

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 addresses a potential crash when platform views are disposed asynchronously during rendering. The core change in PlatformViewEmbedder is the addition of a guard in compositeEmbeddedView that checks if a platform view is still known to the PlatformViewManager before proceeding with composition. To validate this fix, a new test file, async_rendering_test.dart, is introduced. This test simulates the specific race condition by disposing of a platform view within an artificial asynchronous gap in the rendering pipeline, and then confirms that the rendering process completes without crashing.

@harryterkelsen harryterkelsen force-pushed the fix-async-frame-render-issues branch from 98757ce to 3fc6e2d Compare March 13, 2026 22:13
@harryterkelsen
Copy link
Contributor Author

/gemini review

@harryterkelsen harryterkelsen added CICD Run CI/CD and removed CICD Run CI/CD labels Mar 13, 2026
Check if platform views still exist in PlatformViewManager before
compositing to avoid crashes if they are disposed during async gaps
in the rendering pipeline.

Added test/ui/async_rendering_test.dart.
Copy link
Contributor

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

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 correctly addresses a crash when a platform view is disposed asynchronously during the rendering pipeline. The fix involves checking if the view still exists before compositing and changing a debug assertion to a warning to handle the race condition gracefully. The new tests are well-written and verify the fix. I have one suggestion to reduce code duplication in the new test file.

mdebbar
mdebbar previously approved these changes Mar 13, 2026
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for fixing this quickly!

@harryterkelsen harryterkelsen force-pushed the fix-async-frame-render-issues branch from 3fc6e2d to b943f30 Compare March 14, 2026 00:04
@harryterkelsen harryterkelsen added CICD Run CI/CD and removed CICD Run CI/CD labels Mar 14, 2026
@mdebbar mdebbar added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App and removed CICD Run CI/CD labels Mar 16, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 16, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 16, 2026

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

@github-actions github-actions bot removed the CICD Run CI/CD label Mar 16, 2026
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Mar 16, 2026
@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2026
@github-actions github-actions bot removed the CICD Run CI/CD label Mar 17, 2026
@harryterkelsen harryterkelsen added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Mar 17, 2026
@harryterkelsen harryterkelsen requested a review from mdebbar March 17, 2026 20:57
mdebbar
mdebbar previously approved these changes Mar 17, 2026
@flutter-zl flutter-zl self-requested a review March 17, 2026 21:02
flutter-zl
flutter-zl previously approved these changes Mar 17, 2026
Copy link
Contributor

@flutter-zl flutter-zl left a comment

Choose a reason for hiding this comment

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

LGTM

@harryterkelsen harryterkelsen dismissed stale reviews from flutter-zl and mdebbar via 6ae5f89 March 17, 2026 21:15
@github-actions github-actions bot removed the CICD Run CI/CD label Mar 17, 2026
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Mar 17, 2026
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

LGTM! Small question about whether or not to nag the user in release builds for this case (before this change we used to NOT nag users in release builds, only when asserts were enabled)

Comment on lines +377 to +378
debugInvalidViewIds ??= <int>[];
debugInvalidViewIds.add(viewId);
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to "nag" the user in production with the invalid view warning? Should this be: "populate the debugInvalidViewIds array when asserts are enabled, but skip rendering an invalid viewId regardless"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before this change we would crash in the case where we went to render a scene with a platform view where !PlatformViewManager.instance.knowsViewId(viewId). I think downgrading from crash to a warning is okay here. If it turns out that the warning is logged often in normally behaving apps, then we should reconsider and just have it print the warning in an assert or something.

@auto-submit auto-submit bot added this pull request to the merge queue Mar 18, 2026
Merged via the queue into flutter:master with commit 537bb2c Mar 18, 2026
185 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 19, 2026
flutter/flutter@d117642...dd64978

2026-03-18 [email protected] Roll Skia from 2fb5fa71eb12 to f0a13e5efbad (2 revisions) (flutter/flutter#183830)
2026-03-18 [email protected] Roll Skia from ae3d36cb9e29 to 2fb5fa71eb12 (3 revisions) (flutter/flutter#183823)
2026-03-18 [email protected] Linux reuse sibling (flutter/flutter#183653)
2026-03-18 [email protected] Roll Skia from 84a180a1fa80 to ae3d36cb9e29 (4 revisions) (flutter/flutter#183812)
2026-03-18 [email protected] fix(web): handle asynchronously disposed platform views (flutter/flutter#183666)
2026-03-17 [email protected] (Test cross-imports) Remove legacy Material import from sliver_constraints_test (flutter/flutter#183351)
2026-03-17 [email protected] Fix Android Studio pluginsPath when version is unknown (do not use 0.0) (flutter/flutter#182681)
2026-03-17 [email protected] Fixes animation glitch into bottom sheet (flutter/flutter#183303)
2026-03-17 [email protected] Handle#6537 second grouped test (flutter/flutter#182529)
2026-03-17 [email protected] Add a Clarification for the docs of suggestionsBuilder of SearchAnchor (flutter/flutter#183106)
2026-03-17 [email protected] Remove obsolete null checks from style guide (flutter/flutter#181703)
2026-03-17 [email protected] [Impeller] Do not delete the GL object in a HandleGLES if the handle has a cleanup callback (flutter/flutter#183561)
2026-03-17 [email protected] Encode source file patches as UTF-8 in the code formatter script (flutter/flutter#183761)
2026-03-17 [email protected] Fix widget inspector control layout and add safe area regression test (flutter/flutter#180789)
2026-03-17 [email protected] Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)" (flutter/flutter#182522)
2026-03-17 [email protected] fix(web): fix crash in Skwasm when transferring non-transferable texture sources (flutter/flutter#183799)
2026-03-17 [email protected] Roll Skia from dba893a44d7a to 84a180a1fa80 (7 revisions) (flutter/flutter#183803)
2026-03-17 [email protected] Framework: Improve DropdownButton selectedItemBuilder assertion (flutter/flutter#183732)
2026-03-17 [email protected] Add mainAxisAlignment to NavigationRail (flutter/flutter#183514)
2026-03-17 [email protected] Update android triage process to not look at unassigned p1s every week (flutter/flutter#183805)
2026-03-17 [email protected] Adds macos impeller new gallery transition perf test. (flutter/flutter#183802)
2026-03-17 [email protected] fix(web_ui): move prepareToDraw after raster to improve concurrency and stability (flutter/flutter#183791)
2026-03-17 [email protected] [build] Generate debug info for assembly. (flutter/flutter#183425)
2026-03-17 [email protected] [web] Fix occasional failure to find Chrome tab (flutter/flutter#183737)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux_web web_platform_tests_wasm_shard] Cannot render platform views [google_sign_in] Flake in flexible_size_html_element_view_test.dart

5 participants