Skip to content

Commit 936edad

Browse files
authored
[Blazor] rendering - event callbacks change detection (#35493)
1 parent 0e6e65b commit 936edad

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

aspnetcore/blazor/performance/rendering.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ The last two steps of the preceding sequence continue recursively down the compo
2828

2929
To prevent rendering recursion into a particular subtree, use either of the following approaches:
3030

31-
* Ensure that child component parameters are of primitive immutable types, such as `string`, `int`, `bool`, `DateTime`, and other similar types. The built-in logic for detecting changes automatically skips rerendering if the primitive immutable parameter values haven't changed. If you render a child component with `<Customer CustomerId="item.CustomerId" />`, where `CustomerId` is an `int` type, then the `Customer` component isn't rerendered unless `item.CustomerId` changes.
32-
* Override <xref:Microsoft.AspNetCore.Components.ComponentBase.ShouldRender%2A>:
33-
* To accept nonprimitive parameter values, such as complex custom model types, event callbacks, or <xref:Microsoft.AspNetCore.Components.RenderFragment> values.
31+
* Ensure that child component parameters are of specific immutable types&dagger;, such as `string`, `int`, `bool`, and `DateTime`. The built-in logic for detecting changes automatically skips rerendering if the immutable parameter values haven't changed. If you render a child component with `<Customer CustomerId="item.CustomerId" />`, where `CustomerId` is an `int` type, then the `Customer` component isn't rerendered unless `item.CustomerId` changes.
32+
* Override [`ShouldRender`](xref:blazor/components/rendering#suppress-ui-refreshing-shouldrender), setting it to `false`:
33+
* When parameters are nonprimitive types or unsupported immutable types&dagger;, such as complex custom model types or <xref:Microsoft.AspNetCore.Components.RenderFragment> values.
3434
* If authoring a UI-only component that doesn't change after the initial render, regardless of parameter value changes.
3535

36+
&dagger;For more information, see [the change detection logic in Blazor's reference source (`ChangeDetection.cs`)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/Components/src/ChangeDetection.cs).
37+
38+
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
39+
3640
The following airline flight search tool example uses private fields to track the necessary information to detect changes. The previous inbound flight identifier (`prevInboundFlightId`) and previous outbound flight identifier (`prevOutboundFlightId`) track information for the next potential component update. If either of the flight identifiers change when the component's parameters are set in [`OnParametersSet`](xref:blazor/components/lifecycle#after-parameters-are-set-onparameterssetasync), the component is rerendered because `shouldRender` is set to `true`. If `shouldRender` evaluates to `false` after checking the flight identifiers, an expensive rerender is avoided:
3741

3842
```razor

0 commit comments

Comments
 (0)