Open egil opened 1 year ago
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Background and Motivation
In bUnit and other custom renderers for Blazor there may be a need to pass new parameters to a rendered component directly, perhaps because the component is a "root" component and has no parent component that can be used to pass new parameters to it via the normal render tree method.
The (internal, public in .NET 8)
ComponentState
type has aSetDirectParameters
method that is internal, but should be used instead of calling the publicIComponent.SetParametersAsync
directly for all internal states in theRenderer
and related types to be updated correctly (I assume).In addition to this, it will be beneficial if the Renderer would enter into "batch mode" like it does when new parameters are passed from a parent component to a child component. This batches up synchronous re-renders.
Proposed API
The suggestion is to add a
protected void SetDirectParameters(int componentId, ParameterView parameters)
method toRenderer
. It is likely only useful for custom renderers that inherit fromRenderer
, hence there is no reason for this to be public.This method should also toggle "batch render mode" on before passing the new parameters to the component, ensuring re-render, after the new parameters are set, behaves in a similar way as if the parameters were passed to the component from a parent component.
Alternative Designs
Make the
ComponentState.SetDirectParameters
method public. See #48980.Risks
More public APIs that the team has to support and may limit their abilities to change things in the future.
Notes
In bUnit, we are planning to do this via reflection instead of calling
IComponent.SetParametersAsync
going forward.Our version of the
SetDirectParameters(int componentId, ParameterView parameters)
method is doing the following:_isBatchInProgress = true
var state = GetRequiredComponentState(componentId)
state.SetDirectParameters(parameters)
, catching any exceptions thrown by the method passing an exception toHandleException
._isBatchInProgress = false
regardless of the outcome ofstate.SetDirectParameters
.ProcessPendingRender()
method.