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
@@ -89,13 +138,31 @@ The following counter component example persists counter state during prerenderi
89
138
90
139
protected override void OnInitialized()
91
140
{
92
-
CurrentCount ??= Random.Shared.Next(100);
93
-
Logger.LogInformation("CurrentCount set to {Count}", CurrentCount);
141
+
if (CurrentCount == 0)
142
+
{
143
+
CurrentCount = Random.Shared.Next(100);
144
+
Logger.LogInformation("CurrentCount set to {Count}", CurrentCount);
145
+
}
146
+
else
147
+
{
148
+
Logger.LogInformation("CurrentCount restored to {Count}", CurrentCount);
149
+
}
94
150
}
95
151
96
152
private void IncrementCount() => CurrentCount++;
97
153
}
98
154
```
155
+
-->
156
+
157
+
When the component executes, `CurrentCount` is only set once during prerendering. The value is restored when the component is rerendered. The following is example output.
158
+
159
+
> [!NOTE]
160
+
> If the app adopts [interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing) and the page is reached via an internal [enhanced navigation](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling), prerendering doesn't occur. Therefore, you must perform a full page reload for the component to see the following output. For more information, see the [Interactive routing and prerendering](#interactive-routing-and-prerendering) section.
> :::no-loc text=" CurrentCount restored to 96":::
99
166
100
167
In the following example that serializes state for multiple components of the same type:
101
168
@@ -283,6 +350,16 @@ The following counter component example persists counter state during prerenderi
283
350
}
284
351
```
285
352
353
+
When the component executes, `currentCount` is only set once during prerendering. The value is restored when the component is rerendered. The following is example output.
354
+
355
+
> [!NOTE]
356
+
> If the app adopts [interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing) and the page is reached via an internal [enhanced navigation](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling), prerendering doesn't occur. Therefore, you must perform a full page reload for the component to see the following output. For more information, see the [Interactive routing and prerendering](#interactive-routing-and-prerendering) section.
When the component executes, `currentCount` is only set once during prerendering. The value is restored when the component is rerendered. The following is example output.
346
421
347
422
> [!NOTE]
348
-
> If the app adopts [interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing) and the page is reached via an internal [enhanced navigation](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling), prerendering doesn't occur. Therefore, you must perform a full page reload for the `PrerenderedCounter2`component to see the following output. For more information, see the [Interactive routing and prerendering](#interactive-routing-and-prerendering) section.
423
+
> If the app adopts [interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing) and the page is reached via an internal [enhanced navigation](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling), prerendering doesn't occur. Therefore, you must perform a full page reload for the component to see the following output. For more information, see the [Interactive routing and prerendering](#interactive-routing-and-prerendering) section.
> :::no-loc text=" currentCount restored to 96":::
354
429
430
+
:::moniker-end
431
+
355
432
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.
356
433
357
434
The persisted prerendered state is transferred to the client, where it's used to restore the component state. During client-side rendering (CSR, `InteractiveWebAssembly`), the data is exposed to the browser and must not contain sensitive, private information. During interactive server-side rendering (interactive SSR, `InteractiveServer`), [ASP.NET Core Data Protection](xref:security/data-protection/introduction) ensures that the data is transferred securely. The `InteractiveAuto` render mode combines WebAssembly and Server interactivity, so it's necessary to consider data exposure to the browser, as in the CSR case.
0 commit comments