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) thatInteractiveServer
andInteractiveAuto
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 overrideResolveComponentForRenderMode
and just returncomponentActivator.CreateInstance(componentType)
, so that no rendermode-specific behavior is introduced.It would still be a bit odd that
InteractiveServer
orInteractiveWebAssembly
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:
- Just changing WebViewRenderer to do this directly. BlazorWebView has no access to the renderer because it's privately created in the core types here: )
- 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