Skip to content

[iOS/Mac] BlazorWebView: reload the requested page when the web content process ends before it starts loading - #40455

Merged
kubaflo merged 2 commits into
candidate/11.0.1xx-sr2from
fix/candidate-blazor-reload-pending-page
Nov 20, 2026
Merged

kubaflo merged 2 commits into
candidate/11.0.1xx-sr2from
fix/candidate-blazor-reload-pending-page

Conversation

@kubaflo

@kubaflo kubaflo commented Nov 19, 2026 •

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!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

This targets candidate/11.0.1xx-sr2, the same base as #40419. WebContentProcessReloader exists only on the SR2 candidate; it is not in net11 or main.

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

BlazorWebViewTests.WebContentProcessTerminationBeforeFirstPageLoadsLoadsThatPageAgain was added in #40419. It fails on iOS for both the Mono and CoreCLR legs of the candidate's device-test build 1690816 (head 8e70055):

System.TimeoutException : controlDiv never became 'Static' after the reload. Last value: '<null>'.

Root cause. The test ends the web content process from UrlLoading, which runs inside DecidePolicy for the first navigation, before that navigation starts. By the time ContentProcessDidTerminate is called, WebKit has already reset its page load state (PageLoadState::reset), so WKWebView.Url and BackForwardList.CurrentItem are both null. WebContentProcessReloader.TryReload assumed that "the page that was being loaded is still the web view's URL". It therefore fell back to Reload(), which has nothing to load, and the page never loaded.

Temporary diagnostics confirmed this on an iOS 26.0 simulator. For this test the callback saw url=<null> current=<null> visible=True, so the reload ran immediately (no window wait) and still had no URL.

WebKit avoids this with its own pending API request. WebPageProxy::tryReloadAfterProcessTermination loads pendingAPIRequestURL again when it is set, and calls reload() only otherwise. pendingAPIRequest is set by loadRequest and cleared when that navigation starts (didStartProvisionalLoadForFrame). It isn't exposed through WKWebView.

Fix.

  • WebContentProcessReloader mirrors WebKit's pending API request. PageRequested remembers the page MAUI last asked for with LoadRequest, and NavigationStarted (DidStartProvisionalNavigation) forgets it.
  • TryReload loads that page again when it is still pending. Otherwise it keeps the existing behavior: load Url when there's no committed page, else Reload().
  • IOSWebViewManager calls PageRequested for both of its LoadRequest calls: the start page in NavigateCore, and the app-scheme redirect re-issue.
  • The URL is stored as a string because NavigateCore disposes its NSUrl.
  • No test, public API or existing reload/throttle/window-wait behavior changes.

Intentional difference from WebKit: WebKit also drops the pending request when the policy decision ignores that navigation. Here the page stays pending until a navigation starts. If the app cancels its start page in UrlLoading and the process later ends before any navigation starts, the reload asks for that page again. It still goes through DecidePolicy/UrlLoading, so the app's decision still applies.

Causal evidence. iOS 26.0 iPhone 11 Pro simulator, Xcode 27.2. Each run used the full BlazorWebView device-test suite:

pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project BlazorWebView -Platform ios -DeviceUdid <udid> -OutputDirectory artifacts/<run> -SkipXcodeVersionCheck
Run Tree Result
Baseline 8e70055 (candidate head) Red: 61 passed, 1 failed (this test, same '<null>' error as CI), 1 skipped
Fix this PR Green: 62 passed, 0 failed, 1 skipped
Fix reverted production change stashed Red: 61 passed, 1 failed (same test, same error), 1 skipped
Restored this PR Green: 62 passed, 0 failed, 1 skipped

All six WebContentProcessTermination* tests pass with the fix:

  • RaisesProcessTerminatedAndReloadsVisiblePage
  • ReloadsHiddenPageOnceItIsInAWindow
  • RightAfterReloadDoesNotReloadAgain
  • LongAfterReloadReloadsAgain
  • BeforeFirstPageLoadsLoadsThatPageAgain
  • AfterThePageNavigatedByItselfReloadsTheNewPage (added in 4bb40d5 after review; fails if NavigationStarted doesn't clear the pending request, otherwise 63 passed, 0 failed, 1 skipped)

dotnet format whitespace --verify-no-changes passes on both files. MacCatalyst shares this code (iOS/ folder) and was not run locally. In build 1690816 its BlazorWebView work items passed 62/63 at 8e70055 without this change, on macOS 15 (Helix c7a22071) and macOS 26 (Helix cf4220c0), so only iOS shows the failure. This PR's CI covers MacCatalyst with the change.

CI on merge 151ca05: maui-pr 1691141 succeeded. Device tests 1691443 succeeded with 0 failed tests in all 9 runs (Android, iOS, MacCatalyst, Windows). All six tests above pass in the iOS Mono and CoreCLR runs on macOS 15 and 26 and in both MacCatalyst runs. Without this change, a rerun of 1690816's failed jobs at 8e70055 failed the same test again: across both attempts it failed 4 of 4 iOS runs on macOS 26 and 1 of 4 on macOS 15.

Issues Fixed

No separate issue is logged. This is a follow-up to #40419, found while auditing the SR2 candidate (#40116).

…nt process ends before it starts loading

When the web content process ends before the requested page's navigation
starts, WebKit has already cleared the web view's URL and back-forward item
by the time ContentProcessDidTerminate is called. WebContentProcessReloader
then fell back to Reload(), which had nothing to load, so the page never
loaded (WebContentProcessTerminationBeforeFirstPageLoadsLoadsThatPageAgain).

WebKit itself loads its pending API request URL again in that case
(WebPageProxy::tryReloadAfterProcessTermination). Remember the page asked
for with LoadRequest until its navigation starts, and load it again.

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

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 19, 2026
@MauiBot

MauiBot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@kubaflo — existing-test verification; Setup did not capture a tested commit.

Result INCONCLUSIVE Platform Android


🧪 Gate analysis — click to expand

⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect.

No interpretable test-group summary was produced. No additional test execution is inferred.

Setup did not capture a verified PR head; no commit is claimed as tested.

No immutable without-fix baseline was prepared.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 19, 2026

@github-actions github-actions 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.

Expert Review — 1 finding

Reviewed commit 87202a5.

See inline comments for details.

…eload request

When the page navigates by itself (location.href) after a manager-requested
load, the reloader must recover to the page the web view navigated to, not
to the stale requested URL. Fails if NavigationStarted stops clearing
_requestedPageUrl.

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

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 19, 2026
@MauiBot

MauiBot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@kubaflo — existing-test verification; Setup did not capture a tested commit.

Result INCONCLUSIVE Platform Android


🧪 Gate analysis — click to expand

⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect.

No interpretable test-group summary was produced. No additional test execution is inferred.

Setup did not capture a verified PR head; no commit is claimed as tested.

No immutable without-fix baseline was prepared.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 19, 2026

@github-actions github-actions 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.

Expert Review — 0 findings

Reviewed commit 4bb40d5.

@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@kubaflo
kubaflo merged commit 8591389 into candidate/11.0.1xx-sr2 Nov 20, 2026
47 checks passed
@kubaflo
kubaflo deleted the fix/candidate-blazor-reload-pending-page branch November 20, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants