Skip to content

iOS: Fix flake when backgrounding platform views - #190816

Merged
cbracken merged 1 commit into
flutter:masterfrom
cbracken:fix-flake-platformviews-bg
Aug 10, 2026
Merged

iOS: Fix flake when backgrounding platform views#190816
cbracken merged 1 commit into
flutter:masterfrom
cbracken:fix-flake-platformviews-bg

Conversation

@cbracken

Copy link
Copy Markdown
Member

Previously, bringLayersIntoView:withCompositionOrder: started with a FML_DCHECK(self.flutterView), which aborts when an app with platform views on screen is backgrounded.

Before flutter-team-archive/engine#53826, SubmitFrame ran entirely on the platform thread. It started with FML_DCHECK([[NSThread currentThread] isMainThread]) and bailed out early when flutter_view_ was null. BringLayersIntoView sat in the same (synchronous) scope as that check, which ensured the assertion passed.

That change split the method in two: the null check stayed with the raster thread work in SubmitFrame, and the UIKit work moved into PerformSubmit, posted to the platform thread. The isMainThread assertion moved over with it; the flutter_view_ one didn't, so ended up being reached on a different thread at a later point than the check that was guarding it. Since flutterView is a weak ref that surfaceUpdated:NO clears on backgrounding, it might be gone by the time the posted task runs.

We now check and bail out early instead, before
_previousCompositionOrder is cleared, since nothing was attached this frame. applyMutators already does this in the same deferred task.

This doesn't change opt builds (including debug opt builds), which drop DCHECKs at compile time.

No new tests: this fixes a flake that
MultiplePlatformViewsBackgroundForegroundTest in the iOS Scenario app keeps hitting in my local testing.

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.

Previously, `bringLayersIntoView:withCompositionOrder:` started with a
`FML_DCHECK(self.flutterView)`, which aborts when an app with platform
views on screen is backgrounded.

Before flutter-team-archive/engine#53826, `SubmitFrame` ran entirely on the platform
thread. It started with `FML_DCHECK([[NSThread currentThread]
isMainThread])` and bailed out early when `flutter_view_` was null.
`BringLayersIntoView` sat in the same (synchronous) scope as that check,
which ensured the assertion passed.

That change split the method in two: the null check stayed with the
raster thread work in `SubmitFrame`, and the UIKit work moved into
`PerformSubmit`, posted to the platform thread. The isMainThread
assertion moved over with it; the `flutter_view_` one didn't, so ended
up being reached on a different thread at a later point than the check
that was guarding it. Since `flutterView` is a weak ref that
`surfaceUpdated:NO` clears on backgrounding, it might be gone by the
time the posted task runs.

We now check and bail out early instead, before
`_previousCompositionOrder` is cleared, since nothing was attached this
frame. `applyMutators` already does this in the same deferred task.

This doesn't change opt builds (including debug opt builds), which drop
`DCHECK`s at compile time.

No new tests: this fixes a flake that
`MultiplePlatformViewsBackgroundForegroundTest` in the iOS Scenario app
keeps hitting in my local testing.
@cbracken
cbracken requested a review from a team as a code owner August 10, 2026 00:00
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 10, 2026
@flutter-dashboard

Copy link
Copy Markdown

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 you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Aug 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 modifies the bringLayersIntoView:withCompositionOrder: method in FlutterPlatformViewsController.mm to replace the FML_DCHECK(self.flutterView) assertion with a null check on flutterView, returning early if it is nil. There are no review comments, and I have no feedback to provide.

@cbracken cbracken changed the title iOS: Fix abort when backgrounding platform views iOS: Fix flake when backgrounding platform views Aug 10, 2026
@cbracken
cbracken added this pull request to the merge queue Aug 10, 2026
Merged via the queue into flutter:master with commit 2dc0d10 Aug 10, 2026
23 checks passed
@cbracken
cbracken deleted the fix-flake-platformviews-bg branch August 10, 2026 06:19
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-ios iOS applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants