Repository navigation
Pass a FeatureContext to Components.Platform feature factories - #69993
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
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
|
/review |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
|
Copilot's local review panel found no issues to raise at this commit. |
|
@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! |
|
✅ 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
|
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.GetOrAddFeaturenow takesFunc<FeatureContext, T>instead ofFunc<IJSRuntime, T>.Windowcreates oneFeatureContextfor the scope and passes it to every factory. TodayFeatureContextholds onlyIJSRuntime, and Web Storage and Cookie Store now read it from there.Why now
The goal is to fix the shape of the factory before more families start to use it.
Windowowns 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. WithFunc<IJSRuntime, T>, the factory of such a family has to capturewindow, so each read of the property allocates a closure. When the events design is settled, these parts go intoFeatureContext, and the factories staystatic.Window. The Navigator PR (Add Navigator to Microsoft.AspNetCore.Components.Platform #69968) adds an internalNavigator.GetOrAddFeature<T>(Func<FeatureContext, T>)for families such as Clipboard. It delegates to the cache onWindow. 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
Windowitself to the factory. A family would then reach everything onWindow, 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