Skip to content

[iOS] Fix Infinite Measure Looping on iOS - #38197

Merged
kubaflo merged 10 commits into
dotnet:inflight/currentfrom
HarishwaranVijayakumar:fix-37892
Sep 11, 2026
Merged

kubaflo merged 10 commits into
dotnet:inflight/currentfrom
HarishwaranVijayakumar:fix-37892

Conversation

@HarishwaranVijayakumar

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details:

  • A ScrollView can enter an infinite layout and measure-invalidation loop when its content height is effectively equal to its viewport height. The repeated layout invalidations keep the UI thread busy, making the application unresponsive.
  • The reproduction depends on device dimensions, text wrapping, font measurements, and safe-area geometry because these factors determine whether the content lands precisely at the ScrollView scrollability boundary.

Root Cause of the issue:

  • This regression was introduced by [net10.0] Fix SafeArea management on iOS #30629, which updated safe-area measurement and arrangement behavior in MauiScrollView.

  • Near the scrollability boundary, UIKit can alternate AdjustedContentInset between zero and a microscopic floating-point value. Although this difference is much smaller than one physical pixel and has no visible effect, .NET MAUI compares the raw inset values exactly and treats every fluctuation as a meaningful change.

  • Each reported inset change causes MauiScrollView to invalidate its measure and the measures of its ancestors. Remeasuring the layout causes UIKit to recalculate the adjusted inset, producing another tiny change and repeating the cycle:

    Subpixel adjusted-inset change
    → measure invalidation
    → ancestor remeasurement
    → adjusted-inset recalculation
    → another subpixel change
    → infinite layout loop
    

Description of Change

Test coverage and reproduction:

  • Added new test case and reproduction page (Issue37892) to detect and verify infinite measure/layout loops in ScrollView on iOS. The test uses automation to check for loop detection and layout settling, and is skipped on iOS 26+ where the issue cannot be reliably reproduced.

Safe area and layout logic improvements:

  • Changed internal representation of system-adjusted content inset in MauiScrollView from UIEdgeInsets to SafeAreaPadding for consistency and improved comparison logic. (src/Core/src/Platform/iOS/MauiScrollView.cs)
  • Updated safe area validation logic to use pixel-level equality checks (EqualsAtPixelLevel and new IsEmptyAtPixelLevel) to avoid unnecessary invalidations and layout recalculations, preventing the infinite layout loop caused by subpixel inset fluctuations. (src/Core/src/Platform/iOS/MauiScrollView.cs, src/Core/src/Platform/iOS/SafeAreaPadding.cs)
  • Ensured arrangement logic in MauiScrollView uses the updated pixel-level empty check for _systemAdjustedContentInset to further prevent spurious layout passes. (src/Core/src/Platform/iOS/MauiScrollView.cs)

Issues Fixed

Fixes #37892

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before After
Beforefix-37892.mov
Afterfix-37892.mov

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38197

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38197"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 4, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@HarishwaranVijayakumar! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 4, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@Tamilarasan-Paranthaman Tamilarasan-Paranthaman added the area-safearea Issues/PRs that have to do with the SafeArea functionality label Sep 4, 2026
@kubaflo

This comment has been minimized.

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 2 findings

See inline comments for details.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-failed AI could not verify tests catch the bug s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 4, 2026
@HarishwaranVijayakumar HarishwaranVijayakumar changed the title [WIP] [iOS] Fix Infinite Measure Looping on iOS [iOS] Fix Infinite Measure Looping on iOS Sep 9, 2026
@MauiBot MauiBot added s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates and removed s/agent-fix-win AI found a better alternative fix than the PR s/agent-review-in-progress AI review is currently running for this PR labels Sep 11, 2026
@kubaflo

kubaflo commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

could you please resolve conflicts

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## Description

Adds `10.0.110` to both version dropdowns in the bug report issue
template:

- Version with bug
- Last version that worked well

This keeps the dropdowns consistent for the .NET 10 SR11 release.
@kubaflo

kubaflo commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Performance Review Summary

@HarishwaranVijayakumar — performance review results are available based on commit 5546d74.

Timing Improvement advisory Correctness Passed in measured scenarios Platform iOS


📊 Performance Results
Measurement Base Head Result
Subpixel noise 1 (median) 115.63 ms 16.15 ms Improvement advisory (-86.0%)
Subpixel noise 2 (median) 110.53 ms 15.68 ms Improvement advisory (-85.8%)
Subpixel noise 3 (median) 108.78 ms 15.54 ms Improvement advisory (-85.7%)
Full-pixel change 1 (median) 112.09 ms 108.90 ms Neutral (-2.8%)
Full-pixel change 2 (median) 109.71 ms 105.64 ms Neutral (-3.7%)
Full-pixel change 3 (median) 110.02 ms 104.47 ms Neutral (-5.0%)
Subpixel managed bytes/callback (mean) 1,632.55 B 64.01 B -96.1%

Timings are per 1,000 injected inset callbacks. Three ABBA blocks per workload, 24 launches total, 120,000 measured changes per variant/workload. Subpixel timing ranges never overlapped; full-pixel ranges did. Allocation measures the managed UI thread, not native memory.

Experimental native ScrollView workloads: quarter-pixel noise and one-pixel changes, against merge-base b96aa03. iPhone 11 Pro simulator, iOS 18.5, ARM64 Mono, Release. Both builds used the approved SDK 10.0.100 substitution and Xcode-version-check override rather than the exact requested toolchain.


🔧 Findings & Follow-up

Redundant remeasurement is suppressed: subpixel changes went from 1,000 to 0 ScrollView measure callbacks per batch. Full-pixel changes still produced 1,000 on both revisions, with essentially unchanged managed allocation.

Native inset/geometry checks passed, and unchanged-inset callbacks caused no remeasurement on either revision.

Scope: these are controlled inset injections through the real MauiScrollView callback path, not reproduction of the original page freeze or a whole-app/frame-rate benchmark. They are not whole-PR merge clearance. Raw results and comparisons are retained locally.

kubaflo and others added 2 commits September 12, 2026 00:07
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## Description

Adds `11.0.0-rc.1` to both version dropdowns in the bug report issue
template:

- Version with bug
- Last version that worked well

This keeps the dropdowns current for the .NET 11 RC1 release.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

## Summary

Advance `main` to the .NET 10 SR12 development cycle now that
`release/10.0.1xx-sr11` has been cut from the merge of dotnet#37393
(`e047434fd22752a3e96187d55cd554a4a1c200b5`).

Change only `PatchVersion` in `eng/Versions.props` from `110` to `120`.
Keep `SdkBandVersion=10.0.100`, `PreReleaseVersionLabel=ci.main`
(including the inflight override), and `StabilizePackageVersion=false`
unchanged.

This is separate from the SR11 servicing-flip PR and does not change the
release branch.

Related: dotnet#38210.

## Validation

- Evaluated `eng/Versions.props` using `dotnet msbuild -getProperty`:
version `10.0.120`, SDK band `10.0.100`, prerelease label `ci.main`,
stable versions disabled.
- Ran the repository formatter scoped to `eng/Versions.props` and
confirmed the final diff is exactly one changed line.
kubaflo
kubaflo previously approved these changes Sep 11, 2026
Resolve the MauiScrollView safe-area conflict by retaining main's shared live UIKit compensation predicate and making its inset check tolerant at device-pixel precision.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 169298fa-95aa-47a4-ad1c-512dc3f97871
Copilot AI review requested due to automatic review settings September 11, 2026 22:23
@kubaflo

kubaflo commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Resolved the conflicts with current main and pushed merge commit f57a4aee02 to fix-37892.

The MauiScrollView.cs resolution preserves main’s shared live UIKitCompensatesForSafeArea predicate in both validation and arrangement, while incorporating this PR’s device-pixel tolerance via IsEmptyAtPixelLevel(). This avoids selecting the arrange path from stale cached inset state and still suppresses microscopic UIKit inset fluctuations.

Validation completed:

  • Microsoft.Maui.BuildTasks.slnf rebuilt successfully
  • iOS Core, HostApp, and shared UI-test projects built successfully
  • Issue37892.ScrollViewLayoutShouldSettle passed on an iPhone 17 simulator running iOS 26.5 (1 passed, 0 failed)

GitHub now reports the PR as mergeable; remaining BLOCKED status is from normal branch requirements/checks.

@kubaflo
kubaflo changed the base branch from main to inflight/current September 11, 2026 22:25
@kubaflo
kubaflo merged commit 360c206 into dotnet:inflight/current Sep 11, 2026
3 of 13 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Sep 11, 2026

Copilot AI 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.

🟡 Changes recommended

Unresolved test guards, alert detection, and safe-area cache invalidation issues remain.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (3)

src/Controls/tests/TestCases.HostApp/Issues/Issue37892.cs:181

  • The PR description says this test is skipped on iOS 26+, but this branch explicitly applies IOS26BoundaryConfiguration and then continues into the settle assertion. As written, iOS 26 runs the test rather than skipping it; either return/skip before the polling loop or update the description to document the iOS 26-specific reproduction configuration.
		if (IsIOS26OrHigher())
		{
			ApplyConfiguration(IOS26BoundaryConfiguration);
			await Task.Delay(TimeSpan.FromMilliseconds(100));

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue37892.cs:27

  • FindElements(string) performs an accessibility-id query, but the repro supplies Layout Loop Detected only as the DisplayAlert title and does not set that as an AutomationId. This branch therefore cannot observe the loop alert; it waits the full 15 seconds and reports the generic settle timeout instead of the intended loop-specific failure. Use HasStatus("Layout Loop Detected") here or give the alert state an explicit automation id.
			if (App.FindElements("Layout Loop Detected").Count > 0)

src/Core/src/Platform/iOS/MauiScrollView.cs:441

  • Although this new comparison is pixel-level, a sub-pixel change in a non-empty _safeArea still reaches the exact oldSafeArea.Equals check immediately below and calls InvalidateConstraintsCache(). That clears the measure/arrange cache, so the next LayoutSubviews remeasures even though ValidateSafeArea returns true at line 454; repeated UIKit inset fluctuations can therefore still drive a local measure/arrange loop. Compare _safeArea at pixel level for this cache invalidation as well.
			if (!_systemAdjustedContentInset.EqualsAtPixelLevel(systemAdjustedContentInset))
			{
				InvalidateConstraintsCache();
				_systemAdjustedContentInset = systemAdjustedContentInset;
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +19 to +20
public void ScrollViewLayoutShouldSettle()
{
kubaflo added a commit that referenced this pull request Sep 15, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 18, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 21, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 27, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 27, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 3, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 3, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 6, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 6, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Issue Details:

- A `ScrollView` can enter an infinite layout and measure-invalidation
loop when its content height is effectively equal to its viewport
height. The repeated layout invalidations keep the UI thread busy,
making the application unresponsive.
- The reproduction depends on device dimensions, text wrapping, font
measurements, and safe-area geometry because these factors determine
whether the content lands precisely at the `ScrollView` scrollability
boundary.

### Root Cause of the issue:

- This regression was introduced by #30629, which updated
safe-area measurement and arrangement behavior in `MauiScrollView`.
- Near the scrollability boundary, UIKit can alternate
`AdjustedContentInset` between zero and a microscopic floating-point
value. Although this difference is much smaller than one physical pixel
and has no visible effect, .NET MAUI compares the raw inset values
exactly and treats every fluctuation as a meaningful change.
- Each reported inset change causes `MauiScrollView` to invalidate its
measure and the measures of its ancestors. Remeasuring the layout causes
UIKit to recalculate the adjusted inset, producing another tiny change
and repeating the cycle:

  ```text
  Subpixel adjusted-inset change
  → measure invalidation
  → ancestor remeasurement
  → adjusted-inset recalculation
  → another subpixel change
  → infinite layout loop
  ```

### Description of Change

**Test coverage and reproduction:**

* Added new test case and reproduction page (`Issue37892`) to detect and
verify infinite measure/layout loops in `ScrollView` on iOS. The test
uses automation to check for loop detection and layout settling, and is
skipped on iOS 26+ where the issue cannot be reliably reproduced.

**Safe area and layout logic improvements:**

* Changed internal representation of system-adjusted content inset in
`MauiScrollView` from `UIEdgeInsets` to `SafeAreaPadding` for
consistency and improved comparison logic.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)
* Updated safe area validation logic to use pixel-level equality checks
(`EqualsAtPixelLevel` and new `IsEmptyAtPixelLevel`) to avoid
unnecessary invalidations and layout recalculations, preventing the
infinite layout loop caused by subpixel inset fluctuations.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`,
`src/Core/src/Platform/iOS/SafeAreaPadding.cs`)
* Ensured arrangement logic in `MauiScrollView` uses the updated
pixel-level empty check for `_systemAdjustedContentInset` to further
prevent spurious layout passes.
(`src/Core/src/Platform/iOS/MauiScrollView.cs`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #37892

### Tested the behavior in the following platforms
 
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac

### Output
 
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2906a921-4905-4276-836a-3d96db15e85f">
| <video
src="https://github.com/user-attachments/assets/da9cf3c0-f19f-499f-b7dc-1350e3ba3399">
|








<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-scrollview ScrollView area-safearea Issues/PRs that have to do with the SafeArea functionality community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite Measure Looping on iOS (we missed at lest one)

6 participants