Skip to content

Add the Screen Orientation API to Microsoft.AspNetCore.Components.Platform - #70562

Merged
maraf merged 2 commits into
dotnet:mainfrom
jsakamotoIGJP:components-platform-screen-orientation
Nov 16, 2026
Merged

maraf merged 2 commits into
dotnet:mainfrom
jsakamotoIGJP:components-platform-screen-orientation

Conversation

@jsakamotoIGJP

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 Screen Orientation API to Microsoft.AspNetCore.Components.Platform

Description

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

A family below Screen

Screen gets an internal GetOrAddFeature, the same as the one that Navigator got in #69968. It passes the factory to Window, so ScreenOrientation is cached and disposed with the scope like every other family. Window.Screen now passes the window to the Screen constructor through the factory argument, as Window.Navigator does. The public API of Screen does not change.

ScreenOrientation acquires its own JS reference with the path "screen.orientation", not through the reference that Screen holds. A browser without it, such as Safari before 16.4, fails the acquisition with NotSupportedException, as Cookie Store does.

OrientationType, the first Web IDL enum without a default

OrientationType follows #69991 like CookieSameSite, but the Web IDL gives it no default value. So it stores the string as it is, and only default(OrientationType) has no string. Its Value throws InvalidOperationException, and ToString() returns an empty string, so the debugger and logging still work. The existing converter handles it with no change.

Event is also in #70530

The change event is a plain Event. The online and offline events PR (#70530) adds the same empty Event class. I added it here too on purpose, so that the two PRs can be reviewed and merged in either order. The PR that merges second will take the class from the first.

Same choices as the other families

These are not new in this PR. I note them here because reviews of the earlier families asked about them.

  • The E2E tests extend PlatformTestApp.E2E.Tests, the Playwright suite on Microsoft.AspNetCore.Components.Testing that this package has used since [Prototype] Typed browser platform APIs for Blazor, starting with Web Storage #69305. Every family of the package has its tests there, and they run in CI.
  • Disposal does not wait for a pending acquisition, so a reference that arrives after the scope ends is not released. The porting skill accepts this on purpose (.github/skills/port-components-platform-api/SKILL.md, "Implement"). Storage, CookieStore, Navigator, and Screen work the same way.
  • When the token is canceled while the reference cannot be acquired, AddEventListenerAsync throws NotSupportedException, not OperationCanceledException, as CookieStore does (Add event listeners to Microsoft.AspNetCore.Components.Platform #70340).

Trimming

I checked two trimmed WebAssembly apps.

  • In an app that calls only Window.Screen.GetWidthAsync(), ScreenOrientation, OrientationType, Event, and the event listener code were removed.
  • In an app that reads GetTypeAsync() and adds a change listener, GetAngleAsync() was removed. OrientationType keeps its constructor and properties for JSON.

Tests

  • Unit tests cover the reference lifetime as for the other families, the missing screen.orientation, and the change event. They also have the tests that the porting skill lists for an enum without a default. Each value is sent and read as its exact string, and an unknown string is kept. default(OrientationType) equals only itself, and sending it throws before anything reaches the browser.
  • The E2E tests read the type and the angle in both render modes, dispatch change from the page's own JavaScript, and check that a removed listener receives nothing. They use the same result marker as the other tests.
  • One more E2E test rotates the screen with a mobile viewport in Playwright, so the browser fires change itself, and then reads landscape-primary and 90. Only Chromium emulates the orientation, so the test is inconclusive in other browsers.
  • I ran the unit tests and the E2E tests locally, both from the build output and from the output of dotnet publish.

Contributes to #70561
Contributes to #69872

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Nov 13, 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 13, 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 13, 2026 05:00
@jsakamotoIGJP
jsakamotoIGJP requested a review from a team as a code owner November 13, 2026 05:00
Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:00

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.

🔵 Needs a closer look

Missing frozen source-role and head/base evidence, along with the existing-feedback snapshot, prevented the required independent revision-bound validation and feedback-deduplication checks.

No open issues 🎉

What changed in this PR

Adds typed Screen Orientation access to Microsoft.AspNetCore.Components.Platform, implementing proposal #70561 and completing the screen-orientation portion of the browser context work in #69872.

Changes:

  • Exposes Window.Screen.Orientation with asynchronous type and angle reads, change listeners, and scope-managed lifetime.
  • Adds the string-backed OrientationType, preserving unknown browser values, plus a shared empty Event type.
  • Extends unit tests, the demo, and browser tests for reads, listener removal, and Chromium-emulated rotation.
File Description
src/​Components/​Platform/​testassets/​PlatformTestApp.E2E.Tests/​Tests/​ScreenTests.cs Tests orientation reads and events in both render modes.
src/​Components/​Platform/​testassets/​PlatformTestApp.Client/​Components/​ScreenDemo.razor Adds orientation controls and listener cleanup.
src/​Components/​Platform/​test/​ScreenTest.cs Tests child-feature caching and scope disposal.
src/​Components/​Platform/​test/​ScreenOrientationTest.cs Covers lifetime, unsupported APIs, events, and value serialization.
src/​Components/​Platform/​test/​PublicApiTest.cs Applies public-surface checks to ScreenOrientation.
src/​Components/​Platform/​src/​WindowScreenExtensions.cs Passes the owning window into Screen.
src/​Components/​Platform/​src/​ScreenScreenOrientationExtensions.cs Exposes the cached Screen.Orientation property.
src/​Components/​Platform/​src/​ScreenOrientation.cs Implements orientation reads, listeners, and disposal.
src/​Components/​Platform/​src/​Screen.cs Delegates child-feature management to the window.
src/​Components/​Platform/​src/​PublicAPI.Unshipped.txt Records the new public API surface.
src/​Components/​Platform/​src/​OrientationType.cs Defines string-backed orientation values and equality.
src/​Components/​Platform/​src/​Event.cs Adds the payload type for events without additional data.

Review effort: Balanced

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

Two source-supported candidates remain unresolved and are included as advisory inline comments: (1) a pending screen.orientation acquisition can complete after scope disposal without releasing the resulting JS reference, but no binding late-cleanup contract is present; (2) browser-orientation tests conflict with the prescribed Components Selenium boundary, but frozen source does not establish a concrete red/green false-pass. No verified new defect was established.

Per-guide completion: docs/CrossCuttingGuidance.md complete; docs/BlazorComponentsGuidance.md complete. Both used gpt-5.6-sol with runtime-default effort. Runtime/browser/CI/test execution and security assessment were excluded by the supplied policies. Public API approval remains human-owned.

Existing feedback: The frozen feedback snapshot contained no equivalent supported finding to deduplicate. Feedback posted after bundle preparation was not observable.

Other assessed paths: The source supported listener cleanup, cancellation, exception propagation/logging, serialization, feature caching, and completed-reference disposal; no additional behavioral finding was established.

Provenance and boundary: Evidence came only from the ready version-2 frozen bundle for head 897ea9d3889cd8c606f41c84f0bd89e75b8c0c1c, merge base/base tip 59835e6087e90b972a905dc303523cfbb5d828ef, with reviewer guidance frozen at 59835e6087e90b972a905dc303523cfbb5d828ef. No target code, tests, browser workflows, or CI were executed. Tracked Git bytes only; symlink, submodule, and LFS targets cannot establish behavior.

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

@PureWeen

PureWeen commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

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

Informational note on hosted /review [UNRESOLVED] comments (non-blocking, no action needed):

  • ScreenOrientation.cs:111: Not awaiting or disposing an in-flight window.screen.orientation reference that resolves after Screen.DisposeAsync() matches the repository's .github/skills/port-components-platform-api/SKILL.md ("Implement") contract ("Do not wait for a pending acquisition... Release the reference only when the acquisition has already completed successfully. A reference that arrives after disposal is never released. This is accepted.") and existing sibling APIs (Storage, Geolocation, Clipboard).
  • ScreenTests.cs:54: Placing end-to-end tests in src/Components/Platform/test/PlatformTestApp.E2E.Tests (Playwright) matches .github/skills/port-components-platform-api/SKILL.md ("Test": "Exercise the public API in Interactive Server and WebAssembly through PlatformTestApp and PlatformTestApp.E2E.Tests.").

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

Looks good to me 👍 Thank you!

@maraf
maraf merged commit d7870e7 into dotnet:main Nov 16, 2026
31 checks passed
@maraf
maraf temporarily deployed to copilot-pat-pool November 16, 2026 08:41 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 16, 2026 08:41 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 16, 2026 08:42 — with GitHub Actions Inactive
@maraf
maraf temporarily deployed to copilot-pat-pool November 16, 2026 08:45 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Documentation appears necessary, but a draft PR could not be created.

Confidence that documentation is needed: 80%

Drafted a new Blazor article on browser platform APIs covering the Screen Orientation API, and added it to the TOC.

Documentation surfaces considered

  • Conceptual article: Required — New public API (ScreenOrientation, OrientationType, Event, Screen.Orientation) in PublicAPI.Unshipped.txt.
  • Migration guidance: Not required — New additive API; no upgrade action needed.
  • Breaking change: Not required — No existing API or behavior changed; the API is additive.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 02e6a692 Deployed Nov 16, 2026 by maraf via conclusion #324
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants