Skip to content

Review behavior/rules for inheriting components with a RenderModeAttribute #49848

Closed
@SteveSandersonMS

Description

@SteveSandersonMS

Currently RenderModeAttribute does not specify Inherit = false, and the runtime looks up the attribute with a call to componentType.GetCustomAttribute<RenderModeAttribute>().

So, if someone subclasses a component that already has [RenderMode] and puts another [RenderMode] on the subclass, this will fail at runtime ("there is more than one custom attribute of type RenderModeAttribute").

We need to clarify what's meant to happen:

  • If we want to allow this kind of subclassing, we have to change the lookup code to work with it
  • If we don't want to allow it, we should give a better error message or at least document it

An argument could be made that subclassing a component to change its rendermode is dangerous. Components are advised only to specify a rendermode on themselves when they are fundamentally coupled to that mode and can't work in other modes. Therefore if a subclass can force it into a different mode, it's likely to fail or do something unexpected.

On the other hand, in some particular situation, a developer might know what they are doing, and have a valid reason to do this and know it will work in their case. For example maybe they are just changing the Prerender flag or just pointlessly restating the same rendermode a second time.

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions