Repository navigation
Simplify and unify TempData and SupplyParameterFromSession serialization - #65483
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Components Endpoints TempData pipeline to preserve explicit type information per entry, removing heuristic deserialization in JsonTempDataSerializer and simplifying serialization/deserialization.
Changes:
- Switches TempData storage/provider/serializer plumbing from
IDictionary<string, object?>toIDictionary<string, (object? Value, Type? Type)>. - Changes the JSON payload format to store
{ type, value }per entry and removes the prior heuristic-based deserialization paths. - Updates TempData-related tests to account for tuple-based entries and expanded supported types.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/Endpoints/src/TempData/TempData.cs | Stores (Value, Type) per key and adapts IDictionary<string, object?> behavior. |
| src/Components/Endpoints/src/TempData/JsonTempDataSerializer.cs | New { type, value } serialization format; simplified deserialization via stored type. |
| src/Components/Endpoints/src/TempData/ITempDataSerializer.cs | Updates serializer contract to use tuple-based dictionary. |
| src/Components/Endpoints/src/DependencyInjection/ITempDataProvider.cs | Updates provider contract to use tuple-based dictionary. |
| src/Components/Endpoints/src/DependencyInjection/TempDataService.cs | Propagates updated tuple-based dictionary type through the service. |
| src/Components/Endpoints/src/TempData/CookieTempDataProvider.cs | Updates cookie temp data provider to read/write tuple-based values. |
| src/Components/Endpoints/src/TempData/SessionStorageTempDataProvider.cs | Updates session temp data provider to read/write tuple-based values. |
| src/Components/Endpoints/test/TempData/TempDataTest.cs | Updates TempData tests for tuple-based storage (but has remaining outdated cases). |
| src/Components/Endpoints/test/TempData/CookieTempDataProviderTest.cs | Updates cookie provider tests for tuple-based load/save. |
| src/Components/Endpoints/test/TempData/SessionStorageTempDataProviderTest.cs | Updates session provider tests for tuple-based load/save. |
| src/Components/Endpoints/test/TempData/JsonTempDataSerializerTest.cs | Replaces per-type tests with parameterized round-trip tests and expands valid-type coverage. |
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
ilonatommy
left a comment
There was a problem hiding this comment.
I think these are all the ideas from framework review. I didn't go through tests yet. I will do that once the current discussions are resolved 😉
Co-authored-by: Ilona Tomkowicz <[email protected]>
| { | ||
| if (type.IsEnum) | ||
| { | ||
| return "System.Int32"; |
There was a problem hiding this comment.
If we serialize enum it becomes System.Int32 and then when we deserialize, will we deserialize it as enum? Or as int?
There was a problem hiding this comment.
As int. If we want to deserialize it as enum, we need to have AssemblyQualifiedName
There was a problem hiding this comment.
And it's better to change the type than to have AssemblyQualifiedName?
There was a problem hiding this comment.
Or maybe you mean that that's the gain we should have flagged on #65483 (comment)?
There was a problem hiding this comment.
We lose native enum, but it's not a hard transformation that users can't do themselves, so I am not against this trick.
There was a problem hiding this comment.
I added that when we detect enum values we save AssemblyQualifiedName
There was a problem hiding this comment.
Cool! Should we add more test coverage for enums-related paths? We don't do SerializeValue/DeserializeValue with an enum-containing collections, e.g. List<TestEnum>, Dictionary<string, TestEnum>, and TestEnum?[].
ilonatommy
left a comment
There was a problem hiding this comment.
If enum collections are working then it's good to merge.
Simplify and unify TempData and SupplyParameterFromSession serialization
Summary
Reworks how Blazor endpoints serialize stored values so TempData and
[SupplyParameterFromSession]share a single serializer. Stored values include a constrained type token, replacing the heuristic type inference previously used by TempData and enabling session-backed parameters to restore supported enums and collection types using their declared property type.Changes
IStoredDataSerializerandJsonStoredDataSerializer, replacing the TempData-specificITempDataSerializerandJsonTempDataSerializer.[SupplyParameterFromSession].{ "type": "<token>", "value": <json> }. Type tokens omit assembly metadata, andobject[]values are handled recursively so each element retains its own token.int,bool,string,Guid,DateTime,int-backed enums, and nullable forms of those types. Supported containers are single-dimensional arrays,List<T>,HashSet<T>,Collection<T>,Dictionary<string, T>, and recursively storedobject[].System.Int32for TempData payload compatibility across enum types. When[SupplyParameterFromSession]supplies a declared target type, values are deserialized directly to that type so enums and supported collections retain the component property type.[SupplyParameterFromSession]property types when subscriptions are created. Unsupported types fail with a clearInvalidOperationException;objectand abstract property types remain deferred to runtime serialization.ISession.SetandTryGetValueinstead of the previous string-based JSON path. Session keys are normalized to lowercase,nullvalues remove the corresponding entry, and getter failures are logged without preventing other values from being persisted.Currentimplementation as generic enumeration, ensuring enumerated entries are marked as consumed consistently.Testing
JsonTempDataSerializerTestwithJsonStoredDataSerializerTest, covering supported and unsupported types, clean type tokens, scalar and collection round trips, nullable values,int-backed enums, recursiveobject[]values, typed session-value serialization, and byte-identical TempData reserialization.[SupplyParameterFromSession]E2E scenario because arbitrary complex types are no longer supported. Existing E2E coverage continues to verify scalar values, missing values, redirects, and navigation persistence.Breaking Changes
[SupplyParameterFromSession]no longer persists arbitrary complex/custom types. Unsupported concrete property types now fail when the subscription is created, and unsupported runtime values fail during serialization.Fixes #65231