Skip to content

Add the online and offline events to Microsoft.AspNetCore.Components.Platform - #70530

Open
jsakamotoIGJP wants to merge 4 commits into
dotnet:mainfrom
jsakamotoIGJP:components-platform-online-events
Open

jsakamotoIGJP wants to merge 4 commits into
dotnet:mainfrom
jsakamotoIGJP:components-platform-online-events

Conversation

@jsakamotoIGJP

@jsakamotoIGJP jsakamotoIGJP commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Add the online and offline events to Microsoft.AspNetCore.Components.Platform

Description

This implements the API proposal #70529, a part of the browser context family (#69872). The proposal explains the public API. This description covers the implementation.

Nothing new below the public API

The two keys are created with the existing EventTypes.Create, as Window.StorageEvent is. Window.AddEventListenerAsync, the event listener collection, and Platform.ts do not change.

The shape [{}] tells Platform.ts to copy no property of the event object. So the listener receives an empty Event, and no JS object reference is created for the browser event.

Trimming

The keys are static fields of WindowNavigatorExtensions, as Window.StorageEvent is a static field of WindowWebStorageExtensions. I checked two trimmed WebAssembly apps.

  • In an app that calls only Window.Navigator.GetLanguageAsync(), the keys, Event, and the whole event listener code were removed. Reading Window.Navigator does not run the static initializer of the keys.
  • In an app that adds only an online listener, Navigator and the OfflineEvent property were removed. The _offlineEvent field stays, because the static initializer creates both keys. That is one small object, the same as with Window.StorageEvent.

Interactive Server

The XML docs of both keys say that the events are of little use in Interactive Server. I checked this with a temporary E2E test, not in this PR, that wraps WebSocket in the page so that a lost network behaves as it would with a remote server. Playwright's offline mode alone does not stop a WebSocket to localhost.

  • When the connection survived the offline period, the offline listener ran only after the browser was online again, just before the online listener.
  • When the connection was lost, neither listener ran. The browser fired online before Blazor reconnected, and CircuitManager.beginInvokeDotNetFromJS sends on the current connection without queuing the call. The circuit itself reconnected and worked again.

Tests

  • Unit tests check the event names and the shape that reach the browser, and that each listener receives an Event.
  • The E2E tests dispatch online and offline from the page's own JavaScript in both render modes, and check that a removed listener receives nothing. They use the same result marker as the other tests, so a step cannot pass on the text of the previous step.
  • One more E2E test switches the browser offline and back with Playwright, so the browser fires the events itself. It runs in WebAssembly only, because going offline also stalls the Interactive Server circuit, as in the existing onLine test.
  • I ran the unit tests and the E2E tests locally, both from the build output and from the output of dotnet publish.

Contributes to #70529
Contributes to #69872

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Nov 12, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 12, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @jsakamotoIGJP. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jsakamotoIGJP
jsakamotoIGJP marked this pull request as ready for review November 12, 2026 08:37
@jsakamotoIGJP
jsakamotoIGJP requested a review from a team as a code owner November 12, 2026 08:37
Copilot AI balanced review requested due to automatic review settings November 12, 2026 08:37

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

Repeated Watch clicks overwrite registration handles without removing earlier listeners, so Stop watching and component disposal leave callbacks active; registration reuse or cleanup and overlap protection are needed.

1 open issue
What changed in this PR

Adds typed online and offline window events to Components.Platform, extending the browser-context APIs through the existing event-listener infrastructure.

Changes:

  • Adds Window.OnlineEvent, Window.OfflineEvent, and an empty Event payload type.
  • Documents Interactive Server delivery limitations and updates the public API baseline.
  • Adds demo controls, unit coverage, and browser tests for event delivery, listener removal, and WebAssembly network changes.
File Description
src/​Components/​Platform/​testassets/​PlatformTestApp.E2E.Tests/​Tests/​NavigatorTests.cs Tests event delivery, removal, and browser network transitions.
src/​Components/​Platform/​testassets/​PlatformTestApp.Client/​Components/​NavigatorDemo.razor Adds listener controls and event-status output.
src/​Components/​Platform/​test/​NavigatorTest.cs Checks event names, payload shapes, and callbacks.
src/​Components/​Platform/​src/​WindowNavigatorExtensions.cs Defines event keys and documents server limitations.
src/​Components/​Platform/​src/​PublicAPI.Unshipped.txt Records the new public API surface.
src/​Components/​Platform/​src/​Event.cs Defines the empty event payload type.

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

/review

@PureWeen PureWeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[UNRESOLVED] New event tests use Playwright rather than the prescribed Components Selenium surface.

At 593d2d4ae4f3bb05452e38193075309cebeaaeb4, one local review arm raised this concern about src/Components/Platform/testassets/PlatformTestApp.E2E.Tests/Tests/NavigatorTests.cs:71. Its verifier returned DROP/unestablished: the repository policy establishes a suite mismatch, but no missed defect or corresponding red/green assertion evidence was established. The other two arms raised no new findings. This is not a request to move the tests.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Human-directed and GitHub Copilot-generated.

A second Watch click no longer adds another pair of online and offline listeners, and Stop removes listeners that are still being added.
@jsakamotoIGJP

Copy link
Copy Markdown
Contributor Author

Thanks for the review. About the note on Playwright, I'd like to keep the new tests in PlatformTestApp.E2E.Tests. Every family already merged in this package (Web Storage, Cookie Store, Screen, Navigator, and the browser events) has its browser tests there, with Playwright through Microsoft.AspNetCore.Components.Testing, and they were reviewed and merged that way.

@PureWeen

Copy link
Copy Markdown
Member

/review

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

Source-only review of frozen head 67eba201c60fe6e03c6821ab3b8bd6117d9b9645.

One candidate is published inline as unresolved, not as a verified defect: the source establishes that a first registration-task fault skips peer cleanup, but the selective browser/interop failure and subsequent callback delivery require external or immutable validation evidence that is not in the bundle.

Both routed guides completed with gpt-5.6-sol: CrossCuttingGuidance covered API compatibility, async/disposal, trimming, diagnostics, and tests; BlazorComponentsGuidance covered hosting modes, event/JS flow, renderer synchronization, disposal, and browser coverage. Execution of PR code, tests, CI, browser workflows, and samples was excluded; security assessment was excluded by repository guidance. Public API approval and contribution-process metadata remain unresolved human/process evidence.

Existing feedback already covers the Playwright-versus-Components-Selenium permanent-test-surface concern (review 5872006054), so it was not repeated. The earlier duplicate-registration concern (inline thread 4548177054) is addressed at this head by retaining pending/completed tasks with ??=.

No materially changed area was left without a routed guide. Proof is limited to tracked frozen source at head, merge base 9ea8a84d9c7c1a63256d2256969d5a6c66103d83, base tip/guidance commit 59835e6087e90b972a905dc303523cfbb5d828ef, the frozen diff, and feedback prepared before this review. No fresh-feedback check or runtime validation was performed; symlink, submodule, and LFS targets are inert and unavailable.

Generated by ASP.NET Core Pull Request Review for #70530 · copilot · gpt56 · 162.6 AIC · ⌖ 12.4 AIC · ⊞ 18.8K
Comment /review to run again

@PureWeen

Copy link
Copy Markdown
Member

Copilot's local review panel found no issues to raise at this commit.

All three local arms completed at 67eba201c60fe6e03c6821ab3b8bd6117d9b9645 with no verified or question-confidence blocking findings. The earlier repeated-Watch feedback is addressed at this head.

[UNRESOLVED] Interactive Server offline events may retain pending JS interop calls while disconnected.

One arm raised this diagnostic against src/Components/Platform/src/WindowNavigatorExtensions.cs:36. Its verifier returned DROP/unestablished: the frozen evidence did not establish the complete callback-factory path, whether stateful reconnect buffers the call, or browser-event ordering for the proposed offline/online sequence. No runtime reproduction established pending-call accumulation. This is not a confirmed leak or a request for a code change.

Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block agent-reviewed-approved.

Human-directed and GitHub Copilot-generated.

@jsakamotoIGJP

Copy link
Copy Markdown
Contributor Author

Thanks for the note on Interactive Server. I checked this case locally, and the offline call made while the circuit was disconnected was not buffered or sent again after reconnecting. Such a call may stay pending on the JS side, but that is true for any JS-to-.NET call made while disconnected, not something this package adds. Also, in that mode the offline event has to reach .NET over the network that just went down, so it is of little use there anyway, as the <remarks> on both keys say. So I'll leave this as it is.

…nline-events

# Conflicts:
#	src/Components/Platform/src/Event.cs

@kotlarmilos kotlarmilos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 27, 2026

This branch was previously deployed

1 inactive (outdated) deployment
copilot-pat-pool — f2667607 Deployed Nov 12, 2026 by dotnet-policy-service[bot] via pat_pool #2435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed-approved area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants