Skip to content

Commit

Permalink
OnAfterRender lifecycle updates 8.0 (#30098)
Browse files Browse the repository at this point in the history
  • Loading branch information
guardrex authored Aug 18, 2023
1 parent 8347a4c commit 1b97e04
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions aspnetcore/blazor/components/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,28 @@ For more information on route parameters and constraints, see <xref:blazor/funda

## After component render (`OnAfterRender{Async}`)

:::moniker range=">= aspnetcore-8.0"

<!-- UPDATE 8.0 Cross-link server-side rendering (SSR) -->

<xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRender%2A> and <xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRenderAsync%2A> are invoked after a component has rendered interactively and the UI has finished updating (for example, after elements are added to the browser DOM). Element and component references are populated at this point. Use this stage to perform additional initialization steps with the rendered content, such as JS interop calls that interact with the rendered DOM elements.

These methods aren't invoked during prerendering or server-side rendering (SSR) because those processes aren't attached to a live browser DOM and are already complete before the DOM is updated.

For <xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRenderAsync%2A>, the component doesn't automatically rerender after the completion of any returned `Task` to avoid an infinite render loop.

:::moniker-end

:::moniker range="< aspnetcore-8.0"

<xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRender%2A> and <xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRenderAsync%2A> are called after a component has finished rendering. Element and component references are populated at this point. Use this stage to perform additional initialization steps with the rendered content, such as JS interop calls that interact with the rendered DOM elements.

These methods aren't invoked during prerendering because prerendering isn't attached to a live browser DOM and is already complete before the DOM is updated.

For <xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRenderAsync%2A>, the component doesn't automatically rerender after the completion of any returned `Task` to avoid an infinite render loop.

:::moniker-end

The `firstRender` parameter for <xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRender%2A> and <xref:Microsoft.AspNetCore.Components.ComponentBase.OnAfterRenderAsync%2A>:

* Is set to `true` the first time that the component instance is rendered.
Expand Down

0 comments on commit 1b97e04

Please sign in to comment.