Repository navigation
Add the Screen Orientation API to Microsoft.AspNetCore.Components.Platform - #70562
Conversation
|
Thanks for your PR, @jsakamotoIGJP. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
🔵 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.Orientationwith asynchronous type and angle reads, change listeners, and scope-managed lifetime. - Adds the string-backed
OrientationType, preserving unknown browser values, plus a shared emptyEventtype. - 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
|
/review |
There was a problem hiding this comment.
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
|
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):
|
|
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
|
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
ScreenScreengets an internalGetOrAddFeature, the same as the one thatNavigatorgot in #69968. It passes the factory toWindow, soScreenOrientationis cached and disposed with the scope like every other family.Window.Screennow passes the window to theScreenconstructor through the factory argument, asWindow.Navigatordoes. The public API ofScreendoes not change.ScreenOrientationacquires its own JS reference with the path"screen.orientation", not through the reference thatScreenholds. A browser without it, such as Safari before 16.4, fails the acquisition withNotSupportedException, as Cookie Store does.OrientationType, the first Web IDL enum without a defaultOrientationTypefollows #69991 likeCookieSameSite, but the Web IDL gives it no default value. So it stores the string as it is, and onlydefault(OrientationType)has no string. ItsValuethrowsInvalidOperationException, andToString()returns an empty string, so the debugger and logging still work. The existing converter handles it with no change.Eventis also in #70530The
changeevent is a plainEvent. Theonlineandofflineevents PR (#70530) adds the same emptyEventclass. 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.
PlatformTestApp.E2E.Tests, the Playwright suite onMicrosoft.AspNetCore.Components.Testingthat 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..github/skills/port-components-platform-api/SKILL.md, "Implement").Storage,CookieStore,Navigator, andScreenwork the same way.AddEventListenerAsyncthrowsNotSupportedException, notOperationCanceledException, asCookieStoredoes (Add event listeners to Microsoft.AspNetCore.Components.Platform #70340).Trimming
I checked two trimmed WebAssembly apps.
Window.Screen.GetWidthAsync(),ScreenOrientation,OrientationType,Event, and the event listener code were removed.GetTypeAsync()and adds achangelistener,GetAngleAsync()was removed.OrientationTypekeeps its constructor and properties for JSON.Tests
screen.orientation, and thechangeevent. 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.changefrom the page's own JavaScript, and check that a removed listener receives nothing. They use the same result marker as the other tests.changeitself, and then readslandscape-primaryand 90. Only Chromium emulates the orientation, so the test is inconclusive in other browsers.dotnet publish.Contributes to #70561
Contributes to #69872