Repository navigation
Conversation
Resolve framework-owned import map, resource, initializer, TempData, circuit, and persistence payloads through generated contracts. Behavior: changed: fixed framework payloads no longer require reflection metadata State: incomplete - ServerComponentJsonContext is completed by #2 Review hint: application-owned values are deliberately unchanged Co-authored-by: Copilot App <[email protected]>
Generate the server and WebAssembly marker envelopes and route fixed render-fragment wire DTOs through JsonTypeInfo overloads. Application parameter values continue to use the reflection compatibility resolver. Behavior: changed: framework marker envelopes resolve without reflection State: complete Review hint: contracts stop at the application parameter-value boundary Co-authored-by: Copilot App <[email protected]>
Make JSRuntime's reflection fallback explicit, serialize outbound object arrays through JsonTypeInfo, and compose Web renderer and converter-backed contracts before that fallback. Custom events now use the JsonTypeInfo overload. Behavior: changed: framework JS payloads resolve generated or converter-backed contracts first State: builds; focused coverage follows in #4 Review hint: no JS-invokable dispatch metadata is included Co-authored-by: Copilot App <[email protected]>
Exercise reflection-disabled fixed payloads, generated-before-reflection ordering, converter-backed Web renderer arguments, and the corrected custom-event JsonTypeInfo path. Behavior: preserved State: complete for fixed framework serialization Review hint: remote tests prove behavior with STJ reflection disabled Co-authored-by: Copilot App <[email protected]>
Add the minimal RazorComponentsMetadataContext JSON surface and compose registered resolvers into provider-owned persistence, marker, Session, custom-event, Web renderer, and WebAssembly host options. Prerendered and updated WebAssembly markers now deserialize after provider creation through immutable host state. Behavior: changed: application contracts resolve before reflection without crossing service-provider boundaries State: builds; host-isolation coverage follows in #6 Review hint: resolver snapshots are instance-owned; no application resolver mutates a process static Co-authored-by: Copilot App <[email protected]>
Verify resolver composition is additive, existing providers and serializers remain immutable, reflection-disabled marker values use only registered contracts, and WebAssembly host options snapshot each provider. Behavior: preserved State: complete for application JSON composition Review hint: each test builds distinct providers from one service collection to expose resolver leakage Co-authored-by: Copilot App <[email protected]>
Add generic SetAsync overloads and ProtectedBrowserStorageSerializer<T>, while JSON fallback uses the provider-scoped application contract snapshot and preserves shipped constructors. Behavior: changed: applications can provide typed protected-storage serializers or generated JSON contracts State: builds; API and runtime coverage follows in #8 Review hint: direct construction retains the shared compatibility options; DI instances are provider-isolated Co-authored-by: Copilot App <[email protected]>
Cover provider-scoped JSON options, multiple contexts, custom typed serializers, runtime-type fallback, direct-construction compatibility, and failure behavior for protected browser storage. Behavior: preserved State: complete Review hint: the tests exercise both DI-created and shipped-constructor instances Co-authored-by: Copilot App <[email protected]>
Generate the remaining initializer and prerender-state contracts, use explicit JsonTypeInfo overloads for JS component parameters, normalize Server renderer IDs to their integer wire shape, and correct the Endpoints linker substitution target. Behavior: changed: remaining framework-owned payloads no longer depend on reflection or enum wire conversion State: builds; linker descriptor coverage follows in #10 Review hint: these are the final serialization-owned hunks from the frozen donor audit Co-authored-by: Copilot App <[email protected]>
Verify the embedded substitution descriptor targets the assembly that owns the HotReloadManager use so future moves cannot silently reintroduce the Forms assembly name. Behavior: preserved State: complete Co-authored-by: Copilot App <[email protected]>
Create the provider-owned WebAssembly marker serializer on demand when a manually assembled renderer service provider does not register it, while normal hosts continue to reuse the DI singleton. Behavior: preserved: standalone renderer construction continues to emit WebAssembly markers State: complete Review hint: the fallback still snapshots resolver contexts from the current request provider Co-authored-by: Copilot App <[email protected]>
Shared marker settings are linked into nullable-disabled projects, so establish their annotation context locally before declaring nullable application resolvers. Behavior: preserved State: complete Review hint: both files are shared source; the E2ETest compile gate is the regression witness Co-authored-by: Copilot App <[email protected]>
Resolve generated marker and cached render-fragment contracts through ServerComponentSerializationSettings so camelCase naming and null omission remain part of the wire protocol. Behavior: changed: emitted component comments again use lowercase protocol names and omit null-only fields State: complete Review hint: raw start/end marker assertions cover the browser parser contract; direct generated contexts remain only where no custom protocol options apply Co-authored-by: Copilot App <[email protected]>
Materialize provider-deserialized SSR root mappings and insert them before manually configured roots, preserving historical startup precedence without restoring pre-provider deserialization. Behavior: changed: registered marker-backed roots start before manual mappings again State: complete Review hint: two registered and two manual mappings prove order is stable within and across both groups Co-authored-by: Copilot App <[email protected]>
f0a0f88 to
9ca33ec
Compare
There was a problem hiding this comment.
Pull request overview
This PR is the first layer of the Blazor “metadata-first” serialization stack for Native AOT scenarios. It introduces an experimental application metadata registration surface and refactors several Blazor serialization boundaries to prefer source-generated JsonTypeInfo/resolvers (with reflection fallback only when enabled), while keeping serializer option snapshots host/service-provider scoped.
Changes:
- Adds an experimental application metadata API (
RazorComponentsMetadataContext+AddComponentMetadata<TContext>) and resolver composition plumbing. - Switches multiple framework serialization call sites (markers, temp data, JS payloads, persisted state, import maps/resources) to use generated
JsonTypeInfo/resolver chains with reflection-last fallback. - Extends Protected Browser Storage with typed
SetAsync<T>overloads and an opt-in per-typeProtectedBrowserStorageSerializer<T>.
Reviewed changes
Copilot reviewed 77 out of 77 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/Components/WebAssemblyComponentSerializationSettings.cs | Adds CreateOptions and a generated JsonSerializerContext for WebAssembly marker/render-fragment contracts with reflection-last fallback. |
| src/Shared/Components/ServerComponentSerializer.cs | Snapshots per-provider JSON options and serializes via JsonTypeInfo to avoid reflection dependency. |
| src/Shared/Components/ServerComponentSerializationSettings.cs | Adds CreateOptions and a generated JsonSerializerContext for server marker/DTO contracts with reflection-last fallback. |
| src/Shared/Components/PrerenderComponentApplicationStore.cs | Uses generated JsonTypeInfo when serializing prerender persisted state. |
| src/Shared/Components/ComponentJsonMetadata.cs | Introduces a shared helper to compose application resolvers from registered metadata contexts. |
| src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs | Makes resolver fallback explicit (reflection only when enabled) and switches arg serialization to object[] type-info overloads; adds host option replacement hook. |
| src/Components/WebAssembly/WebAssembly/test/TestInternalJSImportMethods.cs | Enhances test JSImport methods to return registered root component metadata from a provided list. |
| src/Components/WebAssembly/WebAssembly/test/Services/WebAssemblyHostSerializationContextTest.cs | Adds test validating resolver snapshot isolation per service provider. |
| src/Components/WebAssembly/WebAssembly/test/Hosting/WebAssemblyHostBuilderTest.cs | Adds test asserting registered root components are inserted before manual mappings. |
| src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyHostSerializationContext.cs | Adds a host-owned serialization context to snapshot component + JSInterop serializer options and parameter deserialization. |
| src/Components/WebAssembly/WebAssembly/src/Services/DefaultWebAssemblyJSRuntime.cs | Creates per-host JSInterop JsonSerializerOptions (ordered resolvers, reflection-last) and installs them via unsafe accessor; uses host context for root updates. |
| src/Components/WebAssembly/WebAssembly/src/Rendering/WebAssemblyRenderer.cs | Switches renderer to use host-scoped JSInterop options rather than process-static options. |
| src/Components/WebAssembly/WebAssembly/src/Prerendering/WebAssemblyComponentParameterDeserializer.cs | Uses host-scoped options and explicit JsonTypeInfo overloads for fragment/union/parameter deserialization. |
| src/Components/WebAssembly/WebAssembly/src/Microsoft.AspNetCore.Components.WebAssembly.csproj | Links in shared converter-backed resolver + fixed JSInterop context + shared component metadata helper. |
| src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs | Defers registered root component parameter deserialization until after service-provider creation; inserts registered mappings ahead of manual ones; installs host serialization context. |
| src/Components/Web/test/WebEventData/WebEventDataTest.cs | Adds tests verifying custom event parsing uses app contracts and base EventArgs doesn’t require contracts. |
| src/Components/Web/test/Rendering/WebRendererJsonResolverTest.cs | Adds tests for resolver ordering, duplication avoidance, and read-only option behavior in out-of-process web renderer scenarios. |
| src/Components/Web/test/Metadata/ComponentMetadataServiceCollectionExtensionsTest.cs | Adds tests for resolver composition, enumerable contexts, provider isolation, and null-argument validation. |
| src/Components/Web/src/WebRenderer.cs | Ensures fixed JSInterop resolver ordering (framework first, converter-backed types before app, reflection last) and uses object[] type-info serialization for in-process attach. |
| src/Components/Web/src/WebEventData/WebEventData.cs | Uses JsonTypeInfo overloads for custom event arg deserialization and handles EventArgs.Empty without contracts. |
| src/Components/Web/src/PublicAPI.Unshipped.txt | Adds new experimental public API entries for metadata registration surface. |
| src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj | Switches linked shared resolver from JsonConverterFactoryTypeInfoResolver to ConverterBackedTypeInfoResolver. |
| src/Components/Web/src/Metadata/RazorComponentsMetadataContext.cs | Adds experimental public base type for application-supplied JSON contracts. |
| src/Components/Web/src/Metadata/ComponentMetadataServiceCollectionExtensions.cs | Adds experimental AddComponentMetadata<TContext> registration and internal metadata services wiring. |
| src/Components/Web/src/Metadata/ComponentJsonMetadataResolver.cs | Adds per-provider resolver snapshot composition from configured resolvers. |
| src/Components/Web/src/Metadata/ComponentJsonMetadataOptions.cs | Introduces resolver list options with a default framework persistent-state context. |
| src/Components/Web/src/JSComponents/JSComponentInterop.cs | Uses explicit JsonTypeInfo overloads when deserializing JS component parameters and JS object references. |
| src/Components/Web/src/Internal/WebPersistentStateJsonContext.cs | Adds a generated context for web persistent-state DTO(s). |
| src/Components/Web/src/Internal/WebJSInteropSerializerContext.cs | Adds a generated context for fixed JSInterop payload types (primitives, arrays, navigation options, etc.). |
| src/Components/Shared/src/RenderFragmentSerializer.cs | Switches fragment attribute/value deserialization to JsonTypeInfo overloads. |
| src/Components/Shared/src/JsonSerializerOptionsProvider.cs | Makes reflection resolver inclusion explicit/conditional when constructing shared options. |
| src/Components/Shared/src/JsonSerialization/JsonConverterFactoryTypeInfoResolver.cs | Removes the previous generic converter-factory-backed resolver implementation. |
| src/Components/Shared/src/JsonSerialization/ConverterBackedTypeInfoResolver.cs | Adds a converter-backed resolver that produces JsonTypeInfo for converter-handled types. |
| src/Components/Server/test/ProtectedBrowserStorageSerializerTest.cs | Adds tests for typed protected storage writes/reads and custom serializer precedence/fallback. |
| src/Components/Server/test/ProtectedBrowserStorageSerializerOptionsTest.cs | Adds tests for protected storage options snapshotting and resolver ordering behavior. |
| src/Components/Server/test/Circuits/CircuitOptionsJavaScriptInitializersConfigurationTest.cs | Adds tests for manifest-driven initializer configuration including reflection-disabled behavior. |
| src/Components/Server/src/PublicAPI.Unshipped.txt | Adds new public API entries for typed protected storage and ProtectedBrowserStorageSerializer<T>. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedSessionStorage.cs | Adds internal ctor to flow serializer options + services provider into base. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedLocalStorage.cs | Adds internal ctor to flow serializer options + services provider into base. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorageSerializerOptions.cs | Adds DI-owned options snapshot builder for protected storage (app resolver first, reflection last). |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorageSerializer.cs | Adds experimental public per-type serializer abstraction for protected storage. |
| src/Components/Server/src/ProtectedBrowserStorage/ProtectedBrowserStorage.cs | Adds typed SetAsync<T> overloads and DI-based typed serializer lookup; snapshots serializer options per instance. |
| src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj | Links shared component metadata helper into Server build. |
| src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs | Wires protected storage DI to use provider-scoped serializer options and enable typed serializer resolution. |
| src/Components/Server/src/Circuits/ServerComponentJsonContext.Server.cs | Extends server component generated context with root operation batch contracts. |
| src/Components/Server/src/Circuits/ServerComponentDeserializer.cs | Snapshots per-provider JSON options and uses explicit JsonTypeInfo overloads for markers and DTOs. |
| src/Components/Server/src/Circuits/RemoteNavigationManager.cs | Sends renderer id as int wire representation for location-changing listener call. |
| src/Components/Server/src/Circuits/RemoteNavigationInterception.cs | Sends renderer id as int wire representation for enable interception call. |
| src/Components/Server/src/Circuits/ComponentParameterDeserializer.cs | Snapshots per-provider options and uses explicit JsonTypeInfo overloads for fragment/union/parameter deserialization. |
| src/Components/Server/src/Circuits/CircuitPersistenceManager.cs | Deserializes persisted marker dictionaries via generated type-info contract. |
| src/Components/Server/src/Circuits/CircuitOptionsJavaScriptInitializersConfiguration.cs | Uses generated string-array contract for module manifest deserialization. |
| src/Components/Server/src/CircuitJavaScriptInitializationMiddleware.cs | Writes initializer payload using generated IList<string> contract to work when reflection serialization is disabled. |
| src/Components/Endpoints/test/TempData/JsonTempDataSerializerTest.cs | Adds reflection-disabled test coverage for “generated-contract-only” temp data serialization support. |
| src/Components/Endpoints/test/LinkerDescriptorTest.cs | Adds test asserting linker substitutions target the Endpoints assembly. |
| src/Components/Endpoints/test/EndpointHtmlRendererTest.cs | Adds raw JSON shape assertions ensuring camelCase/omitted-null protocol markers remain stable. |
| src/Components/Endpoints/test/DependencyInjection/ComponentJsonMetadataIsolationTest.cs | Adds test proving serializer/provider isolation with reflection disabled. |
| src/Components/Endpoints/test/ComponentSerializationSettingsTest.cs | Adds tests verifying generated marker contracts precede reflection and reflection-disabled uses generated-only. |
| src/Components/Endpoints/src/TempData/SessionStorageTempDataProvider.cs | Switches session temp data deserialization to generated JsonTypeInfo. |
| src/Components/Endpoints/src/TempData/JsonTempDataSerializer.cs | Makes generic-interface reflection compatibility path conditional; switches serialization/deserialization to generated JsonTypeInfo. |
| src/Components/Endpoints/src/TempData/CookieTempDataProvider.cs | Switches cookie temp data deserialization to generated JsonTypeInfo. |
| src/Components/Endpoints/src/SessionCascadingValueSupplier.cs | Introduces provider-scoped JSON options with app resolver + conditional reflection fallback and uses JsonTypeInfo overloads. |
| src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs | Uses provider-scoped WebAssembly component serializer instance (or creates one with provider) to include app resolver snapshot. |
| src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs | Serializes start/end markers using options-owned JsonTypeInfo to preserve protocol options and avoid reflection. |
| src/Components/Endpoints/src/Properties/ILLink.Substitutions.xml | Updates linker substitutions target assembly to Endpoints. |
| src/Components/Endpoints/src/Microsoft.AspNetCore.Components.Endpoints.csproj | Links shared component metadata helper into Endpoints build. |
| src/Components/Endpoints/src/DependencyInjection/WebAssemblyComponentSerializer.cs | Converts serializer to instance type with provider-scoped options snapshot and explicit JsonTypeInfo serialization. |
| src/Components/Endpoints/src/DependencyInjection/RazorComponentsServiceCollectionExtensions.cs | Registers ServerComponentSerializer via DI constructor injection (provider-scoped options snapshot). |
| src/Components/Endpoints/src/DependencyInjection/DefaultRazorComponentsServiceOptionsConfiguration.cs | Uses generated contract when parsing JavaScript initializer JSON strings. |
| src/Components/Endpoints/src/CacheView/SerializedRenderFragmentHybridCacheSerializer.cs | Uses explicit JsonTypeInfo in hybrid-cache fragment serializer. |
| src/Components/Endpoints/src/Builder/ResourceCollectionUrlEndpoint.cs | Serializes resource collections using options-owned type-info. |
| src/Components/Endpoints/src/Assets/ImportMapDefinition.cs | Serializes import map with options-owned type-info to avoid reflection. |
| src/Components/Components/test/PersistentState/PersistentStateSerializationOptionsTest.cs | Adds tests for independent ordered option snapshots and reflection-disabled behavior. |
| src/Components/Components/src/PersistentState/PersistentStateSerializationOptions.cs | Adds helper to create ordered per-manager persistent-state options (framework first, app, reflection-last). |
| src/Components/Components/src/PersistentState/PersistentServicesRegistry.cs | Uses generated type-info for registry persistence and adds non-serializable property logging + filtering. |
| src/Components/Components/src/PersistentState/ComponentStatePersistenceManager.cs | Creates PersistentComponentState with per-provider serialization options snapshot and app resolver from DI. |
| src/Components/Components/src/PersistentComponentState.cs | Adds option snapshot support, typed JsonTypeInfo persist/take helpers, and a CanSerialize(Type) check. |
| src/Components/Components/src/Infrastructure/IComponentJsonMetadataResolver.cs | Adds internal abstraction for accessing composed application resolver snapshots. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
Overview
This is stack layer 1/6 for #68332 — Aspire Dashboard Native AOT support, bounded to the live PR diff
66e8a029..9ca33ec5(77 files, 14 commits). It makes Blazor’s serialization boundaries metadata-first: framework contracts are source-generated, application contracts compose ahead of compatibility reflection, and converter-owned JS types remain converter-backed. The cross-cutting constraint is host isolation: application resolvers are snapshotted per service provider/host and never mutate process-static serializer options; later stack layers build on this JSON foundation for JS dispatch, binding, component metadata, framework providers, and the final Native AOT proof.Design
The application-facing JSON surface is deliberately narrow and experimental: one context property and one registration method. It does not expose component, binding, or JS-invokable descriptors owned by later layers.
Protected browser storage adds typed writes and an optional typed serializer while retaining the shipped object overloads, existing constructors, and JSON fallback behavior.
Resolver ordering is intentional and consistent:
ProtectedBrowserStorageSerializer<T>wins before JSONThe rejected alternative was process-static mutation of persistence or marker resolver chains. Instead, serializer/deserializer instances,
ComponentStatePersistenceManager, renderers, and the WebAssembly host own their options snapshots. Therefore a provider already built is immutable; only providers built after anotherAddComponentMetadata<TContext>()call observe the new contracts.Implementation
Framework-owned contracts. The same generated-contract pattern covers four equivalence classes; one representative is shown, with the remaining deltas listed rather than repeated:
JsonTypeInfooverloads.Dictionary<string, JsonElement>shapes; generic-interface reflection remains available only whenJsonSerializer.IsReflectionEnabledByDefault.Protocol options remain authoritative. Generated metadata is resolved through the protocol-owned options rather than serializing directly with a context property. This preserves camel-case field names and null omission while avoiding reflection.
The same options-owned contract rule applies to cached render fragments and marker serializers/deserializers. Raw marker tests assert lowercase
type/prerenderId, absence of PascalCase names, and omission of null-only fields on both start and end comments.Provider-scoped application composition. Registration is additive, but resolution snapshots the list once when the provider creates the singleton resolver.
Consumers fall into three identical ownership groups: persistence (
ComponentStatePersistenceManager/PersistentComponentState), Server/Endpoints markers and Session (serializer/deserializer instances), and protected storage (DI-owned options). Directly constructed legacy instances retain shared compatibility options; DI-created instances snapshot the current provider.JS payloads.
JSRuntimenow installs reflection explicitly only when available and serializes outbound arguments through the existingobject[]type-info contract. Web renderers place fixed contracts and converter-backed references ahead of application contracts.The equivalent inbound deltas are explicit type-info overloads for custom events and JS component parameters;
EventArgs.Emptyneeds no contract. Navigation payloads send the Server renderer ID as its integer wire representation.WebAssembly host timing and order. Initial prerender parameter deserialization is deferred until after service-provider creation, so it can use that host's resolver snapshot. Root-update operations use the same host-owned context. Registered marker-backed roots are then inserted before manual mappings, retaining historical startup precedence and preserving order within both groups.
Protected storage dispatch. The generic path first looks for a closed typed serializer; otherwise it resolves generated JSON metadata from the provider-owned options. Protection and browser I/O are unchanged.
Outcome
ClientRenderingMultpleComponentsTest.CanRenderMultipleRootComponentspassed in Debug JITRestack verification against current
main: all 14/14 commits are patch-identical (range-diff=and matching stable patch IDs), with no dropped or repaired PR patches. Post-restack validation passed Components 36/0, Web 9/0, Endpoints 45/0, Server 51/0, WebAssembly 5/0, JSInterop 56/0, plus the dependency-aware Components E2ETest compile gate with 0 warnings/errors.This PR remains independently reviewable against
main; subsequent stack layers depend on its application JSON registration and host-isolated serializer composition.