Skip to content

[blazor][wasm] Convert more interop to JSImport#65895

Merged
pavelsavara merged 5 commits intodotnet:mainfrom
pavelsavara:wasm_interop_cleanup
Mar 23, 2026
Merged

[blazor][wasm] Convert more interop to JSImport#65895
pavelsavara merged 5 commits intodotnet:mainfrom
pavelsavara:wasm_interop_cleanup

Conversation

@pavelsavara
Copy link
Copy Markdown
Member

@pavelsavara pavelsavara commented Mar 21, 2026

  • ConsoleLog
  • NavigateTo
  • Refresh

- NavigateTo
- Refresh
@pavelsavara pavelsavara added this to the .NET 11 Planning milestone Mar 21, 2026
@pavelsavara pavelsavara self-assigned this Mar 21, 2026
@pavelsavara pavelsavara added the area-blazor Includes: Blazor, Razor Components label Mar 21, 2026
pavelsavara and others added 2 commits March 21, 2026 15:49
Co-authored-by: campersau <buchholz.bastian@googlemail.com>
- NotifyLocationChangingAsync
@pavelsavara pavelsavara marked this pull request as ready for review March 22, 2026 06:54
@pavelsavara pavelsavara requested a review from a team as a code owner March 22, 2026 06:54
Copilot AI review requested due to automatic review settings March 22, 2026 06:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 continues the Blazor WebAssembly move away from IJSRuntime-based interop by converting additional navigation and console logging calls to use System.Runtime.InteropServices.JavaScript ([JSImport]) bindings.

Changes:

  • Switch WebAssemblyNavigationManager.NavigateTo and Refresh to [JSImport] calls and introduce a new JS entrypoint (navigateToWithArgs) to avoid passing NavigationOptions as an object.
  • Update WebAssembly console logging to call globalThis.console.* via [JSImport], removing the need to flow WebAssemblyJSRuntime into the logger/provider.
  • Update BasicTestApp and host builder wiring to match the new logger/provider constructors.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Components/test/testassets/BasicTestApp/Program.cs Updates logger provider registration to no longer resolve/pass IJSRuntime.
src/Components/test/testassets/BasicTestApp/PrependMessageLoggerProvider.cs Removes IJSRuntime dependency and uses the updated WebAssemblyConsoleLogger API.
src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyNavigationManager.cs Converts navigation/refresh interop to [JSImport] and adds a dedicated interop wrapper.
src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLoggerProvider.cs Removes WebAssemblyJSRuntime from provider construction and creates loggers without JS runtime injection.
src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyConsoleLogger.cs Replaces InvokeVoid("console.*") usage with [JSImport] console bindings.
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyHostBuilder.cs Updates default logging provider registration to the new constructor.
src/Components/Web.JS/src/Services/NavigationManager.ts Exposes navigateToWithArgs and adds an implementation that matches the new .NET JSImport signature.
src/Components/Shared/src/BrowserNavigationManagerInterop.cs Adds a shared interop constant for the new navigateToWithArgs identifier.

@pavelsavara pavelsavara merged commit 8bba19e into dotnet:main Mar 23, 2026
29 checks passed
@javiercn
Copy link
Copy Markdown
Member

What are we trying to achieve here? There's no related issue and this is introducing a separate path for navigation manager. We don't want to have separate paths for different hosts, and this now introduces two ways of achieving the same thing. The path in server uses a function and the path in wasm uses another. Now we need to be aware of that when we make changes.

I'd like to better understand the rationale behind this change, as it only seems to bring drawbacks. If AOT is the concern, the plan is to more broadly pass in serialization context/options that can be source generated and that are compatible.

@pavelsavara
Copy link
Copy Markdown
Member Author

What are we trying to achieve here?

@javiercn This is in prep for rendering at distance. Perf as side-effect. There will be more.

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.

5 participants