-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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.