- Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis 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)Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)
Milestone
Description
Hi,
This is a follow-up to an issue that was somewhat prematurely closed:
#32163
In short, I would like to access previous values of changed parameters without implementing my own solution. Inspecting the source code, it appears that authors of Blazor at some point already contemplated this feature:
aspnetcore/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs
Lines 526 to 547 in b1c34c8
| // As an important rendering optimization, we want to skip parameter update | |
| // notifications if we know for sure they haven't changed/mutated. The | |
| // "MayHaveChangedSince" logic is conservative, in that it returns true if | |
| // any parameter is of a type we don't know is immutable. In this case | |
| // we call SetParameters and it's up to the recipient to implement | |
| // whatever change-detection logic they want. Currently we only supply the new | |
| // set of parameters and assume the recipient has enough info to do whatever | |
| // comparisons it wants with the old values. Later we could choose to pass the | |
| // old parameter values if we wanted. By default, components always rerender | |
| // after any SetParameters call, which is safe but now always optimal for perf. | |
| // When performing hot reload, we want to force all components to re-render. | |
| // We do this using two mechanisms - we call SetParametersAsync even if the parameters | |
| // are unchanged and we ignore ComponentBase.ShouldRender | |
| var oldParameters = new ParameterView(ParameterViewLifetime.Unbound, oldTree, oldComponentIndex); | |
| var newParametersLifetime = new ParameterViewLifetime(diffContext.BatchBuilder); | |
| var newParameters = new ParameterView(newParametersLifetime, newTree, newComponentIndex); | |
| if (!newParameters.DefinitelyEquals(oldParameters) || diffContext.Renderer.IsHotReloading) | |
| { | |
| componentState.SetDirectParameters(newParameters); | |
| } |
Thank you for your consideration.
SlidEnergy, innermark, rusfield and wstaelens
Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis 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)Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)