Skip to content

[blazor][wasm] use dotnet.download() for InteractiveAuto - #66656

Merged
pavelsavara merged 11 commits into
dotnet:mainfrom
pavelsavara:download_api
Jun 19, 2026
Merged

pavelsavara merged 11 commits into
dotnet:mainfrom
pavelsavara:download_api

Conversation

@pavelsavara

@pavelsavara pavelsavara commented May 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #66439

Summary

When an Auto-rendered component triggers WebAssembly resource loading on the first visit (no cached resources), use the runtime's dotnet.download() API instead of dotnet.create(). This downloads assets into the browser HTTP cache without instantiating the full WASM runtime, reducing memory pressure and CPU overhead while a Blazor Server circuit is actively serving the page.

Motivation

Previously, Auto mode would start the full WebAssembly runtime creation (dotnet.create()) even when the resources weren't cached yet — meaning the user's first visit would pay the cost of both an active Server circuit and full WASM initialization. The only mitigation was throttling parallel downloads to 1 via maxParallelDownloads.

With this change, on the first visit we only populate the HTTP cache (via dotnet.download()). On subsequent visits, the resources are already cached and the full runtime is created immediately.

@pavelsavara pavelsavara added this to the 11.0-preview5 milestone May 12, 2026
@pavelsavara pavelsavara self-assigned this May 12, 2026
@pavelsavara pavelsavara added the area-blazor Includes: Blazor, Razor Components label May 12, 2026
@pavelsavara
pavelsavara marked this pull request as ready for review May 26, 2026 15:21
Copilot AI review requested due to automatic review settings May 26, 2026 15:21
@pavelsavara
pavelsavara requested a review from a team as a code owner May 26, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes Blazor SSR InteractiveAuto behavior in the Components Web.JS layer by prefetching WebAssembly resources via the runtime’s dotnet.download() API when resources are not yet cached, avoiding full WebAssembly runtime instantiation while a Blazor Server circuit is active.

Changes:

  • Update the WebAssembly platform load pipeline to support a “download-only” mode for Auto-rendered components on cold cache.
  • Track resource-hash presence in localStorage to decide whether to prefetch (download-only) vs fully create the runtime.
  • Adjust an enhanced navigation E2E test to avoid stale element references across SSR→interactive transitions, and update the generated dotnet.d.ts typings.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Components/Web.JS/src/Services/WebRootComponentManager.ts Adds Auto-mode decision to use “download-only” when resources aren’t believed cached; persists a cache marker in localStorage.
src/Components/Web.JS/src/Platform/Platform.ts Extends Platform.load signature to accept an optional justDownload flag.
src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts Implements download-only path using dotnet.download() and defers dotnet.create() until needed.
src/Components/Web.JS/src/Boot.WebAssembly.Common.ts Wires justDownload through the platform load path and conditionally marks the platform as loaded.
src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs Updates staleness checks to use <html> and waits for interactivity before asserting DOM preservation.
src/Components/dotnet-runtime-js/dotnet.d.ts Updates generated runtime typings, including download(httpCacheOnly?: boolean).

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@pavelsavara

Copy link
Copy Markdown
Member Author

@maraf please review

@pavelsavara
pavelsavara requested a review from maraf May 28, 2026 07:05

@maraf maraf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@pavelsavara
pavelsavara merged commit e80ed94 into dotnet:main Jun 19, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[blazor][wasm] adopt download() runtime API for render mode auto

4 participants