You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/integration.md
+87-6
Original file line number
Diff line number
Diff line change
@@ -402,6 +402,83 @@ In `Pages/_Host.cshtml` of Blazor apps that are `ServerPrerendered` in a Blazor
402
402
</body>
403
403
```
404
404
405
+
:::moniker-end
406
+
407
+
:::moniker range=">= aspnetcore-10.0"
408
+
409
+
<!-- UPDATE 10.0 - API cross-link -->
410
+
411
+
Decide what state to persist using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service. The `[SupplyParameterFromPersistentComponentState]` attribute applied to a property registers a callback to persist the state during prerendering and loads it when the component renders interactively or the service is instantiated.
412
+
413
+
In the following example, the `{TYPE}` placeholder represents the type of data to persist (for example, `WeatherForecast[]`).
414
+
415
+
```razor
416
+
@code {
417
+
[SupplyParameterFromPersistentComponentState]
418
+
public {TYPE} Data { get; set; }
419
+
}
420
+
```
421
+
422
+
In the following example, the `WeatherForecastPreserveState` component persists weather forecast state during prerendering and then retrieves the state to initialize the component. The [Persist Component State Tag Helper](xref:mvc/views/tag-helpers/builtin-th/persist-component-state-tag-helper) persists the component state after all component invocations.
Decide what state to persist using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service. <xref:Microsoft.AspNetCore.Components.PersistentComponentState.RegisterOnPersisting%2A?displayProperty=nameWithType> registers a callback to persist the component state before the app is paused. The state is retrieved when the application resumes. Make the call at the end of initialization code in order to avoid a potential race condition during app shutdown.
406
483
407
484
In the following example:
@@ -449,7 +526,7 @@ In the following example:
449
526
}
450
527
```
451
528
452
-
The following example is an updated version of the`FetchData` component based on the Blazor project template. The`WeatherForecastPreserveState` component persists weather forecast state during prerendering and then retrieves the state to initialize the component. The [Persist Component State Tag Helper](xref:mvc/views/tag-helpers/builtin-th/persist-component-state-tag-helper) persists the component state after all component invocations.
529
+
In the following example, the `WeatherForecastPreserveState` component persists weather forecast state during prerendering and then retrieves the state to initialize the component. The [Persist Component State Tag Helper](xref:mvc/views/tag-helpers/builtin-th/persist-component-state-tag-helper) persists the component state after all component invocations.
By initializing components with the same state used during prerendering, any expensive initialization steps are only executed once. The rendered UI also matches the prerendered UI, so no flicker occurs in the browser.
535
616
536
617
The persisted prerendered state is transferred to the client, where it's used to restore the component state. [ASP.NET Core Data Protection](xref:security/data-protection/introduction) ensures that the data is transferred securely in Blazor Server apps.
@@ -969,7 +1050,7 @@ To solve these problems, Blazor supports persisting state in a prerendered page
969
1050
970
1051
Decide what state to persist using the <xref:Microsoft.AspNetCore.Components.PersistentComponentState> service. <xref:Microsoft.AspNetCore.Components.PersistentComponentState.RegisterOnPersisting%2A?displayProperty=nameWithType> registers a callback to persist the component state before the app is paused. The state is retrieved when the application resumes. Make the call at the end of initialization code in order to avoid a potential race condition during app shutdown.
971
1052
972
-
The following example is an updated version of the`FetchData` component based on the Blazor project template. The`WeatherForecastPreserveState` component persists weather forecast state during prerendering and then retrieves the state to initialize the component. The [Persist Component State Tag Helper](xref:mvc/views/tag-helpers/builtin-th/persist-component-state-tag-helper) persists the component state after all component invocations.
1053
+
In the following example, the `WeatherForecastPreserveState` component persists weather forecast state during prerendering and then retrieves the state to initialize the component. The [Persist Component State Tag Helper](xref:mvc/views/tag-helpers/builtin-th/persist-component-state-tag-helper) persists the component state after all component invocations.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/lifecycle.md
+45-3
Original file line number
Diff line number
Diff line change
@@ -594,7 +594,7 @@ Prerendering waits for *quiescence*, which means that a component doesn't render
594
594
595
595
Welcome to your new app.
596
596
597
-
<SlowComponent />
597
+
<Slow />
598
598
```
599
599
600
600
> [!NOTE]
@@ -616,6 +616,46 @@ When the `Home` component is prerendering, the `Slow` component is quickly rende
616
616
617
617
To address the double rendering of the loading message and the re-execution of service and database calls, persist prerendered state with <xref:Microsoft.AspNetCore.Components.PersistentComponentState> for final rendering of the component, as seen in the following updates to the `Slow` component:
0 commit comments