From 7019709372c596bb04472b71a33c00cdd0bbc168 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Thu, 5 Jan 2023 07:09:42 -0600 Subject: [PATCH] Parent/child initialization order (#28018) --- aspnetcore/blazor/components/lifecycle.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/aspnetcore/blazor/components/lifecycle.md b/aspnetcore/blazor/components/lifecycle.md index 5980602f06..5553a90ee4 100644 --- a/aspnetcore/blazor/components/lifecycle.md +++ b/aspnetcore/blazor/components/lifecycle.md @@ -32,6 +32,8 @@ Component lifecycle events: > [!NOTE] > Asynchronous actions performed in lifecycle events might not have completed before a component is rendered. For more information, see the [Handle incomplete async actions at render](#handle-incomplete-async-actions-at-render) section later in this article. +A parent component renders before its children components because rendering is what determines which children are present. If synchronous parent component initialization is used, the parent initialization is guaranteed to complete first. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + ![Component lifecycle events of a Razor component in Blazor](~/blazor/components/lifecycle/_static/lifecycle1.png) Document Object Model (DOM) event processing: @@ -83,6 +85,8 @@ Although [route parameter matching is case insensitive](xref:blazor/fundamentals and are invoked when the component is initialized after having received its initial parameters in . +If synchronous parent component initialization is used, the parent initialization is guaranteed to complete before child component initialization. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + For a synchronous operation, override : `Pages/OnInit.razor`: @@ -505,6 +509,8 @@ Component lifecycle events: > [!NOTE] > Asynchronous actions performed in lifecycle events might not have completed before a component is rendered. For more information, see the [Handle incomplete async actions at render](#handle-incomplete-async-actions-at-render) section later in this article. +A parent component renders before its children components because rendering is what determines which children are present. If synchronous parent component initialization is used, the parent initialization is guaranteed to complete first. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + ![Component lifecycle events of a Razor component in Blazor](~/blazor/components/lifecycle/_static/lifecycle1.png) Document Object Model (DOM) event processing: @@ -556,6 +562,8 @@ Although [route parameter matching is case insensitive](xref:blazor/fundamentals and are invoked when the component is initialized after having received its initial parameters in . +If synchronous parent component initialization is used, the parent initialization is guaranteed to complete before child component initialization. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + For a synchronous operation, override : `Pages/OnInit.razor`: @@ -978,6 +986,8 @@ Component lifecycle events: > [!NOTE] > Asynchronous actions performed in lifecycle events might not have completed before a component is rendered. For more information, see the [Handle incomplete async actions at render](#handle-incomplete-async-actions-at-render) section later in this article. +A parent component renders before its children components because rendering is what determines which children are present. If synchronous parent component initialization is used, the parent initialization is guaranteed to complete first. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + ![Component lifecycle events of a Razor component in Blazor](~/blazor/components/lifecycle/_static/lifecycle1.png) Document Object Model (DOM) event processing: @@ -1029,6 +1039,8 @@ Although [route parameter matching is case insensitive](xref:blazor/fundamentals and are invoked when the component is initialized after having received its initial parameters in . +If synchronous parent component initialization is used, the parent initialization is guaranteed to complete before child component initialization. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + For a synchronous operation, override : `Pages/OnInit.razor`: @@ -1450,6 +1462,8 @@ Component lifecycle events: > [!NOTE] > Asynchronous actions performed in lifecycle events might not have completed before a component is rendered. For more information, see the [Handle incomplete async actions at render](#handle-incomplete-async-actions-at-render) section later in this article. +A parent component renders before its children components because rendering is what determines which children are present. If synchronous parent component initialization is used, the parent initialization is guaranteed to complete first. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + ![Component lifecycle events of a Razor component in Blazor](~/blazor/components/lifecycle/_static/lifecycle1.png) Document Object Model (DOM) event processing: @@ -1501,6 +1515,8 @@ Although [route parameter matching is case insensitive](xref:blazor/fundamentals and are invoked when the component is initialized after having received its initial parameters in . +If synchronous parent component initialization is used, the parent initialization is guaranteed to complete before child component initialization. If asynchronous parent component initialization is used, the completion order of parent and child component initialization can't be determined because it depends on the initialization code running. + For a synchronous operation, override : `Pages/OnInit.razor`: