Skip to content

[Blazor] Make component serialization metadata-first - #68295

Draft
javiercn wants to merge 8 commits into
mainfrom
javiercn-aot-stack-1-stj
Draft

[Blazor] Make component serialization metadata-first#68295
javiercn wants to merge 8 commits into
mainfrom
javiercn-aot-stack-1-stj

Conversation

@javiercn

@javiercn javiercn commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

Stack layer 1/6 for the Aspire Dashboard Native AOT work. This PR is intentionally limited to System.Text.Json and serialization contracts and targets main independently.

  • generates fixed framework contracts for import maps/resources, JavaScript initializers, TempData, circuit persistence, component marker envelopes, render-fragment wire DTOs, and framework JS payloads
  • exposes the minimal experimental RazorComponentsMetadataContext.JsonTypeInfoResolver surface and AddComponentMetadata<TContext>()
  • composes application contracts ahead of the reflection compatibility resolver using immutable, service-provider-owned snapshots
  • defers WebAssembly prerender parameter deserialization until provider creation and routes later updates through host-owned serialization state
  • adds generic protected browser storage writes and ProtectedBrowserStorageSerializer<T>

Review focus

Please review only the STJ/serialization design in this layer: contract ownership, resolver ordering, provider/host isolation, marker compatibility, and protected storage. JS-invokable descriptors, binding/component metadata, framework providers, and Native AOT E2E proof are intentionally deferred to later stack layers.

Validation

  • Components persistent-state serialization tests
  • Web renderer/custom-event serialization tests
  • Endpoints marker, TempData, Session, render-fragment, and host-isolation tests
  • Server circuit/persistence/marker/protected-storage serialization tests
  • full WebAssembly unit suite
  • JSInterop serialization tests
  • LinkabilityChecker build

Source draft PR #68291 remains open and untouched.

javiercn and others added 8 commits August 8, 2026 20:29
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant