Skip to content

BlazorWebView needs a way to enable overriding ResolveComponentForRenderMode #51235

Description

Image for: Description

Scenario: I have Razor components enabled for various interactivity modes in a Blazor web app, such as specifying @attribute [RenderModeInteractiveServer]. I want to place those components in a Razor Class Library (RCL) and re-use them in a Blazor Hybrid app.

Problem: You get errors stating that the interactivity modes are not supported in BlazorWebView's hybrid renderer.

@Eilon said in a chat:

I can confirm that pages with @attribute [RenderModeInteractiveServer] make Blazor Hybrid sad

@SteveSandersonMS responded:

... Blazor Hybrid's renderer could override ResolveComponentForRenderMode and implement any behavior it wants around resolving rendermodes. The default in the Renderer base class is to throw because it doesn't know what rendermodes would make sense in what cases. But we could say (for example) that InteractiveServer and InteractiveAuto modes should be allowed on Blazor Hybrid and would just be no-ops, because it's already interactive. To do that, the renderer subclass would override ResolveComponentForRenderMode and just return componentActivator.CreateInstance(componentType), so that no rendermode-specific behavior is introduced.

It would still be a bit odd that InteractiveServer or InteractiveWebAssembly would have any meaning for webview. It would sort of make sense if they somehow did use a server or WebAssembly. The fact that they don't is why we didn't think it was right to do this in .NET 8. Maybe we need to reopen the question of having a mode simply called Interactive that for web would require you to configure globally how you want it to be resolved, whereas for WebView would be a no-op.

Enabling this requires some change in the aspnetcore repo, such as:

  1. Just changing WebViewRenderer to do this directly. BlazorWebView has no access to the renderer because it's privately created in the core types here:
    Renderer = new WebViewRenderer(ServiceProvider, dispatcher, ipcSender, loggerFactory, JSRuntime, jsComponents);
    )
  2. Adding some extensibility to enable the change to be made in BlazorWebView and its associated classes

Note: Customers have also noticed this: dotnet/maui#17725

Metadata

Image for: Metadata

Metadata

Image for: Metadata

Assignees

No one assigned

    Labels

    Pillar: Complete Blazor WebPriority:1Work that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-hybridtriaged

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Image for: Issue actions