Skip to content

[Blazor] Accessing collection of changed parameters previous values #32287

@daniel-p-tech

Description

@daniel-p-tech

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:

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-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)

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions