Repository navigation
[release/11.0-preview5] SupplyParameterFromSession support for Blazor - #66756
Merged
wtgodbe merged 1 commit intoMay 20, 2026
Merged
Conversation
lewing
approved these changes
May 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Backports the new Blazor SSR feature [SupplyParameterFromSession], enabling components to declaratively read/write values from ISession (similar to existing [SupplyParameterFromTempData] patterns) during endpoint rendering, plus adds unit/E2E coverage and test-server plumbing to enable session.
Changes:
- Introduces
SupplyParameterFromSessionAttribute(public API) and registers a new session-based cascading value supplier inAddRazorComponents(). - Adds
SessionCascadingValueSupplierto read initial values from session and persist tracked values onResponse.OnStarting. - Adds unit tests and E2E test assets/infra updates to validate SSR and interactive-mode behavior.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/Web/src/SupplyParameterFromSessionAttribute.cs | Adds the new public attribute used to opt-in to session-backed parameter supply. |
| src/Components/Web/src/PublicAPI.Unshipped.txt | Declares the new public API surface for the attribute. |
| src/Components/Endpoints/src/SessionCascadingValueSupplier.cs | Implements session read + OnStarting persistence for supplied parameters. |
| src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.cs | Wires HttpContext into the session supplier during SSR initialization. |
| src/Components/Endpoints/src/DependencyInjection/RazorComponentsServiceCollectionExtensions.cs | Registers SessionCascadingValueSupplier and the supplier mapping for the new attribute. |
| src/Components/Endpoints/test/Session/SessionSubscriptionTest.cs | Adds unit tests validating subscription read semantics + persistence integration. |
| src/Components/Endpoints/test/Session/SessionCascadingValueSupplierTest.cs | Adds unit tests validating callback registration, persistence, error handling, and key behavior. |
| src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsNoInteractivityStartup.cs | Updates test-server configuration to optionally enable session middleware/services. |
| src/Components/test/testassets/Components.TestServer/Components.TestServer.csproj | Adds a reference needed for session middleware in the test server. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/SupplyParameterFromSessionComponent.razor | Adds SSR test page that reads/writes session-backed parameters. |
| src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/SupplyParameterFromSessionNavigationComponent.razor | Adds SSR navigation page to validate persistence across navigation. |
| src/Components/test/testassets/BasicTestApp/SupplyParameterFromSessionInteractive.razor | Adds an interactive-mode component to validate session/tempdata don’t flow there. |
| src/Components/test/testassets/BasicTestApp/Index.razor | Exposes the new interactive test component in the selector list. |
| src/Components/test/E2ETest/Tests/TempDataSessionStorageTest.cs | Ensures session is enabled for TempData session-storage E2E coverage. |
| src/Components/test/E2ETest/Tests/SupplyParameterFromSessionInteractiveTest.cs | Adds interactive-mode E2E coverage for the new attribute (and tempdata). |
| src/Components/test/E2ETest/Tests/SupplyParameterFromSessionAttributeTest.cs | Adds SSR E2E coverage for reading/writing and navigation persistence. |
wtgodbe
approved these changes
May 20, 2026
Member
|
Mac machines are down right now. Change was previously validated against |
Open
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #66528 to release/11.0-preview5
SupplyParameterFromSession support for Blazor
Summary
Adds a new
[SupplyParameterFromSession]attribute that allows Blazor SSR components to declaratively read and write HTTP session data, following the same pattern as[SupplyParameterFromQuery]and[SupplyParameterFromForm].Motivation
Currently, Blazor SSR lacks a simple, declarative way to access session data. Developers who want to persist user-specific data across HTTP requests (like shopping cart contents or multi-step form state) must:
IHttpContextAccessorand manually interact withISessionThis creates inconsistent patterns across applications and increases the likelihood of errors.
Changes
SupplyParameterFromSessionAttribute(Components.Web) — A new public attribute inheriting fromCascadingParameterAttributeBasewith an optionalNameproperty to specify the session key (defaults to the property name).SingleDeliveryisfalse, so values are re-supplied on each render.SessionCascadingValueSupplier(Components.Endpoints) — Internal scoped service that:ISessionviaISessionFeatureand deserializes them usingSystem.Text.Json(withJsonSerializerDefaults.Web)Response.OnStartingcallback to persist all tracked property values back to the session before the response is sentToLowerInvariant())PropertyGetterinstances per component type/property pair using aConcurrentDictionaryInvalidOperationExceptionif multiple components register the same keySessionSubscription(inner class ofSessionCascadingValueSupplier) — On the firstGetCurrentValue()call, reads from the session; on subsequent calls, returns the current component property value (enabling two-way binding). Removes the value callback onDispose.AddRazorComponents()now registersSessionCascadingValueSupplieras a scoped service and wires it as a cascading value supplier forSupplyParameterFromSessionAttribute.EndpointHtmlRenderer— CallsSessionCascadingValueSupplier.SetRequestContext(httpContext)during standard service initialization.PublicAPI.Unshipped.txt:SupplyParameterFromSessionAttributeclass, its constructor, andNameproperty.Usage
Developers must configure session middleware in their application:
Then use the attribute on component properties:
Values are read from the session on first render and automatically persisted back when the response starts.
Testing
SessionCascadingValueSupplierTest) — 10 tests covering: callback registration, duplicate key rejection, value persistence to session, null value removal, multiple keys, exception resilience (both callback and serialization errors), key lowercasing, no-op when session is unavailable, callback deletion, andOnStartingintegration.SessionSubscriptionTest) — 8 tests covering: null whenHttpContextnot set, null for missing keys, value retrieval, key lowercasing, enum deserialization, null on deserialization failure, component-value passthrough on subsequent calls, and fullCreateSubscriptionround-trip.SupplyParameterFromSessionAttributeTest) — 5 Selenium tests covering: reading from session, null for missing keys, redirect persistence, complex type serialization, and cross-navigation persistence.RazorComponentEndpointsNoInteractivityStartupto separate session middleware configuration (--UseSession) from TempData session storage (--UseSessionStorageTempDataProvider), addedMicrosoft.AspNetCore.Sessionreference to test server project, and added two test Razor components.Fixes #64422
Customer Impact
New feature to test in P5.
Regression?
Risk
New feature, no users will be impacted by changes.
Verification
Packaging changes reviewed?
When servicing release/2.3