Open chsienki opened 10 months ago
This is going to be a very common scenario: creating a component that accepts a generic type parameter where the component inside has a strict or very specific rendermode requirements too.
The Virtualize component does not seem to work because of this, as per my recent testing.
Also, the workaround does not work. It produces this error:
"The type or namespace name 'RenderModeInteractiveServerAttribute' could not be found (are you missing a using directive or an assembly reference?)".
I can't seem to find the namespace for RenderModeInteractiveServerAttribute. Is it because it doesn't exist anymore in .NET 8?
This should be given higher priority.
Just ran into this issue as well. The workaround didn't work either since RenderModeInteractiveServer
, along with the other render mode attributes, appear to have been removed in .NET 8 (source).
Just ran into this issue on .NET 8, so workaround does not work.
I think you should be able to create your own attribute with the same effect, for example:
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
class RenderModeInteractiveServer : RenderModeAttribute
{
public override IComponentRenderMode Mode => RenderMode.InteractiveServer;
}
and then the workaround should work:
@attribute [type: RenderModeInteractiveServer]
It works by creating the attribute
I think you should be able to create your own attribute with the same effect, for example:
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; class RenderModeInteractiveServer : RenderModeAttribute { public override IComponentRenderMode Mode => RenderMode.InteractiveServer; }
and then the workaround should work:
@attribute [type: RenderModeInteractiveServer]
This workaround works also in .Net 8 Blazor.
+1 I hit this issue and was surprised to see it's not planning on being fixed.
My workaround, is putting @rendermode="InteractiveWebAssembly"
in the parent component using the problematic component.
I am somewhat surprised (and disappointed) that this is not an easy fix in the .razor codegen and that it won't make it in the next release (https://github.com/dotnet/razor/issues/10193#issuecomment-2030587923). Good to know that there are workarounds for it, though.
+1
Hi, I ran into this issue with @rendermode InteractiveServer
The attribute workaround, worked.
+1 I've had the same issue a couple of times, workaround with custom attribute works in .net8
I've had the same issue, but in my case I wanted to set the prerender attribute as false. Usually, this is the way to go:
@rendermode @(new InteractiveServerRenderMode(prerender: false))
But that wasn't working due to the @typeparam
directive being used, so I tried tweaking the workaround @jjonescz mentioned, like this:
{
public override IComponentRenderMode Mode => new InteractiveServerRenderMode(prerender: false);
}
Unfortunately, that didn't work at all. Luckily, I solved it by setting prerender to false in the parent component, but I wish I could do it to the component itself.
Unfortunately, that didn't work at all.
Not sure why wouldn't that work. What exactly happened? Did you get some errors?
Unfortunately, that didn't work at all.
Not sure why wouldn't that work. What exactly happened? Did you get some errors?
No errors, but prerender was still enabled despite setting it to false.
No errors, but prerender was still enabled despite setting it to false.
I cannot reproduce that. If you can create a minimal repro, please open a separate issue. Thanks.
Got this issue quite a few times now.
This is what components are about right? Complex object made simple by handing out the logic.. Should be given higher priority. Thanks @jjonescz for the workaround!
Just got hit by this one. A fix would be nice although the workaround does work. However it would be nice to remark the requirement of an extra class in the top comment.
Also just hit this when trying to build a Blazor component that requires interactivity. It's unfortunate this doesn't work 😞 I appreciate the workaround, but dislike having to (re-)define magic framework attributes in my own code.
+1
+1
Please consider upvoting the issue instead of commenting "+1". When sorting issues by most upvoted (which we might do to decide what to prioritize), these comments don't have any effect.
Please consider upvoting the issue instead of commenting "+1". When sorting issues by most upvoted (which we might do to decide what to prioritize), these comments don't have any effect.
If you are experiencing this issue, please comment below to help us prioritize this.
+1
Known Issue
There is a known issue that the Razor compiler generates uncompilable C# when specifying a
@rendermode
on a Razor component that also uses the@typeparam
directive.Symptoms
When specifying both
@rendermode
and@typeparam
in a Razor component, the user will receive error similar toCS0305: Using the generic type 'Component<T>' requires '1' type arguments.
Workarounds
A user can specify the rendermode manually via the
@attribute
directive.EDIT: The attribute class needs to be also created as well since it did not ship in .NET after all:
Planned Fix
At this time, there is no fix planned, as it is believed to affect a small number of users. If you are experiencing this issue, please upvote this issue to help us prioritize this.
A compiler update with a clearer error is planned.