Repository navigation
Add Navigator to Microsoft.AspNetCore.Components.Platform - #69968
Conversation
Navigator is the first part of the browser context family. It also owns later families such as Clipboard and Storage Manager, so it comes first. - Add Navigator with the Baseline metadata attributes language, languages, onLine, cookieEnabled, userAgent, hardwareConcurrency, and maxTouchPoints, and the Window.Navigator extension property. It works like Storage. Window shares one instance, the JS reference is acquired on first use, and the DI scope disposes it. - Add the internal Navigator.GetOrAddFeature and FeatureContext, so later families can hang off Navigator with a static factory. The projections stay in the Window cache. Reading Window.Navigator allocates a closure for now; this will be fixed for all families once events are settled. - Add unit tests, the InternalsVisibleTo they need, and the Navigator types to PublicApiTest. - Add demo pages and E2E tests for both render modes. A non-default locale, user agent, and touch support show that each value comes from the browser, and the WebAssembly test also reads onLine while offline.
|
Thanks for your PR, @jsakamotoIGJP. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
ilonatommy
left a comment
There was a problem hiding this comment.
Assuming the design won't be changed, the implementation and coverage looks good. Let's first finish the discussion in #69967 (comment) before merging, though.
…avigator # Conflicts: # src/Components/Platform/src/Microsoft.AspNetCore.Components.Platform.csproj # src/Components/Platform/src/PublicAPI.Unshipped.txt # src/Components/Platform/test/PublicApiTest.cs
# Conflicts: # src/Components/Platform/src/PublicAPI.Unshipped.txt # src/Components/Platform/test/PublicApiTest.cs
There was a problem hiding this comment.
🔵 Needs a closer look
The review materials omit the frozen head/base identities and existing-feedback bundle required by repository guidance, preventing confirmation of independent review completeness.
No open issues 🎉
What changed in this PR
Adds typed access to Window.Navigator in Microsoft.AspNetCore.Components.Platform, implementing proposal #69967 as the first part of the browser context family. It also provides shared caching support for future Navigator-based APIs.
Changes:
- Adds seven asynchronous browser metadata getters, including preferred languages as an
ImmutableArray<string>. - Extends feature factories to accept an argument without capturing closures, while retaining scope-owned caching and disposal.
- Adds unit tests, public API checks, and browser tests covering Interactive Server and WebAssembly, including online-state changes.
| File | Description |
|---|---|
src/Components/Platform/testassets/PlatformTestApp/Components/Pages/NavigatorServer.razor |
Hosts the Navigator demo in Interactive Server mode. |
src/Components/Platform/testassets/PlatformTestApp.E2E.Tests/Tests/NavigatorTests.cs |
Tests browser metadata in both modes and online-state changes in WebAssembly. |
src/Components/Platform/testassets/PlatformTestApp.Client/Pages/NavigatorWebAssembly.razor |
Hosts the Navigator demo in WebAssembly mode. |
src/Components/Platform/testassets/PlatformTestApp.Client/Components/NavigatorDemo.razor |
Provides controls and completion markers for browser tests. |
src/Components/Platform/test/PublicApiTest.cs |
Includes Navigator in asynchronous-method and disposal-surface checks. |
src/Components/Platform/test/NavigatorTest.cs |
Covers property reads, caching, acquisition retries, disposal, and child features. |
src/Components/Platform/src/WindowNavigatorExtensions.cs |
Exposes the cached Window.Navigator property. |
src/Components/Platform/src/Window.cs |
Adds argument-bearing factories to avoid closure allocations. |
src/Components/Platform/src/PublicAPI.Unshipped.txt |
Records the new Navigator public API. |
src/Components/Platform/src/Navigator.cs |
Implements metadata getters, lazy reference acquisition, and scope-owned disposal. |
src/Components/Platform/src/Microsoft.AspNetCore.Components.Platform.csproj |
Grants the unit-test assembly access to internal feature infrastructure. |
Review effort: Balanced
|
/review |
There was a problem hiding this comment.
Source-only review of frozen head b256c29147ad8a1bae545585aea1d19f3b6d3300 found one validated P2 disposal-race issue: a pending Navigator acquisition can complete after its scoped owner is disposed, allowing browser work to continue and leaving the late IJSObjectReference undisposed.
Both routed guides completed independently with gpt-5.6-sol, and the candidate passed the independent verifier. Existing frozen feedback did not already cover this issue. No other unresolved candidates remained; routine negative checks found the Window factory refactor and public API entries consistent. Public API approval remains human-owned.
The review used only the immutable bundle at head b256c29147ad8a1bae545585aea1d19f3b6d3300, merge base/base tip eeceb660128d3d00ea9b35effe4fad3fac3d42e3, with trusted guidance from commit eeceb660128d3d00ea9b35effe4fad3fac3d42e3. Tests, CI, browser workflows, samples, and target code were not executed; security assessment was excluded by repository guidance. Tracked Git bytes only were available, and feedback posted after bundle preparation was not observable.
Generated by ASP.NET Core Pull Request Review for #69968 · copilot · gpt56 · 155.1 AIC · ⌖ 12 AIC · ⊞ 18.8K
Comment /review to run again
|
@ilonatommy I merged |
|
Confidence that documentation is needed: 80% Drafted a docs section on the new Navigator API in the Blazor JS interop article, scoped to .NET 12. Documentation surfaces considered
|
Add Navigator to Microsoft.AspNetCore.Components.Platform
Description
This implements the API proposal #69967, the first part of the browser context family (#69872). The proposal explains the public API. This description covers the implementation.
How later families hang off
NavigatorNavigatoris the first object belowWindowthat other families will hang off, such as Clipboard, Storage Manager, and Web Locks. For them,Navigatorhas an internal method.It delegates to
Window.GetOrAddFeature. So every projection of the scope stays in the one cache onWindow, keeps a stable identity, and is disposed when the scope ends.A Clipboard PR would then add only an extension property like this.
Clipboardwould acquire its own JS reference with the path"navigator.clipboard", not through the reference thatNavigatorholds. JS interop resolves dotted identifiers, so the first call is still one round trip, and a failed acquisition stays inside the family. A missingnavigator.clipboard, such as on an insecure page, still becomesNotSupportedException, as in Cookie Store.Nothing calls
Navigator.GetOrAddFeaturein this PR, so the unit tests call it directly. This is why the library now hasInternalsVisibleTofor its test project.Why
FeatureContextThe factory receives the
FeatureContextthatWindowowns since #69993, the same one that families onWindowget. So a child family gets the parts that the whole scope shares, such as the ones events will add (#69922). Passing theWindowitself would also work. But then a child family could reach everything onWindow, such as other families and window listeners.No closure on each access
Navigator.GetOrAddFeaturepasses the factory toWindow.GetOrAddFeatureas it is. So child families such as Clipboard use astaticlambda and allocate nothing on each access.Navigatoritself needs theWindowto delegate to, so a plain factory for it would capturewindowand allocate a closure on each read ofWindow.Navigator. To avoid this,Windowgets an internal overload that passes an argument to the factory, in the style ofConcurrentDictionary.GetOrAdd.Window.Navigatorcalls it withwindowas the argument and astaticlambda. The existing overloads now go through the same code path.ImmutableArray<string>forlanguagesGetLanguagesAsyncreturnsImmutableArray<string>. This is different from the repo's API conventions (.github/skills/review-public-api/references/conventions.md), which preferIReadOnlyList<T>for returned lists. It was chosen in this comment on #69967, because it keeps the promise ofFrozenArraythat nobody changes the list. The lists that the merged families return will change toImmutableArray<T>in a follow-up PR.The method wraps the deserialized
string[]withImmutableCollectionsMarshal.AsImmutableArray, so it does not copy the array. Nothing else holds a reference to that array.Tests
onLinetest switches the browser offline and back. It runs in WebAssembly only, because going offline also cuts the Interactive Server circuit.GetLanguageAsync(). The otherNavigatormethods and the Web Storage types were removed.dotnet publish.Contributes to #69967
Contributes to #69872