Skip to content

Consider an analyzer to warn if a [Parameter] property isn't a simple auto property #26230

@SteveSandersonMS

Description

@SteveSandersonMS

If a [Parameter] property has setter logic, the setter could be used to cause side effects that create problems, such as infinite rendering loops. There have been reports of side-effects causing unexpected extra rendering and overwriting parameter changes at #24599 (comment)

In general, a [Parameter] property is intended as a framework-managed communication channel between a parent and a child component. Developers shouldn't either (1) write to the parameter themselves, either from inside or outside the component, except when implementing their own SetParametersAsync logic, or (2) trigger any side-effects from the setter.

We should consider adding an analyzer that warns if a [Parameter] property isn't just a simple { get; set; } one. Of course, this could be disruptive for existing apps.

Additionally we should strengthen the documentation about parameters to advise developers that not only should they not overwrite the incoming data on a [Parameter] (because their changes can get lost next time the parent renders), but also they should not cause side-effects from the setter.

Examples of problems this would avoid: #27997, #28518

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-allThis issue impacts all the customersanalyzerIndicates an issue which is related to analyzer experiencearea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-component-modelAny feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)severity-minorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions