Skip to content

Pass a FeatureContext to Components.Platform feature factories - #69993

Merged
ilonatommy merged 5 commits into
dotnet:mainfrom
jsakamotoIGJP:components-platform-feature-context
Nov 6, 2026
Merged

ilonatommy merged 5 commits into
dotnet:mainfrom
jsakamotoIGJP:components-platform-feature-context

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. (Not applicable. The behavior does not change, and the existing tests cover it.)
  • You've included inline docs for your change, where applicable. (Not applicable. The change is internal.)
  • 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.

Pass a FeatureContext to Components.Platform feature factories

Description

This PR changes only internal code in Microsoft.AspNetCore.Components.Platform. The public API does not change.

Window.GetOrAddFeature now takes Func<FeatureContext, T> instead of Func<IJSRuntime, T>. Window creates one FeatureContext for the scope and passes it to every factory. Today FeatureContext holds only IJSRuntime, and Web Storage and Cookie Store now read it from there.

public Storage LocalStorage
    => window.GetOrAddFeature("localStorage", static context => new Storage(context.JSRuntime, "localStorage"));

Why now

The goal is to fix the shape of the factory before more families start to use it.

  • Families with events. They need parts that the whole scope shares. In my trial for the events proposal ([API Proposal] Add browser event listeners to the typed browser platform APIs for Blazor #69922), Window owns a callback factory (one JS module import for each scope) and a logger, and gives each event target a listener collection built from them. Families that take callbacks, such as Web Locks and Geolocation, need the callback factory too. With Func<IJSRuntime, T>, the factory of such a family has to capture window, so each read of the property allocates a closure. When the events design is settled, these parts go into FeatureContext, and the factories stay static.
  • Families below Window. The Navigator PR (Add Navigator to Microsoft.AspNetCore.Components.Platform #69968) adds an internal Navigator.GetOrAddFeature<T>(Func<FeatureContext, T>) for families such as Clipboard. It delegates to the cache on Window. With the old signature it has to wrap the factory in a closure. After this PR it can pass the factory through as it is.

I did not pass the Window itself to the factory. A family would then reach everything on Window, such as other families and window listeners, and none of them needs that.

Tests

I ran the unit tests and the E2E tests locally, both from the build output and from the output of dotnet publish.

Contributes to #69987

@jsakamotoIGJP
jsakamotoIGJP requested a review from a team as a code owner October 23, 2026 08:34
Copilot AI balanced review requested due to automatic review settings October 23, 2026 08:34
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Oct 23, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 23, 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.

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

The required frozen source-and-feedback bundle was not supplied, so approval checks remain incomplete despite no reported findings.

No open issues 🎉

What changed in this PR

This PR introduces an internal FeatureContext for Components.Platform feature factories, preparing for shared services and Navigator child features without changing the public API.

Changes:

  • Add a scope-shared context containing IJSRuntime.
  • Pass that context through Window’s feature factory methods.
  • Update Web Storage and Cookie Store factories to read the runtime from the context.
File Description
src/​Components/​Platform/​src/​WindowWebStorageExtensions.cs Update both storage factories to use the context.
src/​Components/​Platform/​src/​WindowCookieStoreExtensions.cs Update the cookie store factory to use the context.
src/​Components/​Platform/​src/​Window.cs Create and pass one shared context to feature factories.
src/​Components/​Platform/​src/​FeatureContext.cs Add the internal runtime-holding context.

Review effort: Balanced

@PureWeen

Copy link
Copy Markdown
Member

/review

@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 3, 2026
@PureWeen

PureWeen commented Nov 3, 2026

Copy link
Copy Markdown
Member

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

@jsakamotoIGJP

Copy link
Copy Markdown
Contributor Author

@ilonatommy This internal PR is the base for Navigator, Screen, and the next families. Could you decide on it first? I pushed the latest main, so the checks should rerun. Thanks!

@ilonatommy ilonatommy added feature-blazor-jsinterop This issue is related to JSInterop in Blazor and removed pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun labels Nov 6, 2026
@ilonatommy
ilonatommy merged commit 25e9e14 into dotnet:main Nov 6, 2026
39 checks passed
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 5%

No docs needed: internal refactoring of feature factory signature; public API and behavior unchanged.

Documentation surfaces considered

  • Conceptual article: Not required — Internal refactoring only; no user-visible change.
  • Migration guidance: Not required — No user action needed on upgrade.
  • Breaking change: Not required — No public API or behavior change.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 2e190526 Deployed Nov 6, 2026 by ilonatommy via conclusion #210
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 feature-blazor-jsinterop This issue is related to JSInterop in Blazor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants