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
*Theserverversioncantypicallyaccesstheserver-sideresourcesdirectly. Injectingan<xref:System.Net.Http.HttpClient>ontheserverthatmakescallsbacktotheserverisn't recommended, as the network request is typically unnecessary. Alternatively, the API might be external to the server project, but a service abstraction for the server is required to transform the request in some way, for example to add an access token to a proxied request.
*Ifprerenderingisn't required for a WebAssembly component that calls the web API, disable prerendering by following the guidance in <xref:blazor/components/render-modes#prerendering>. If you adopt this approach, you don'tneedtoadd<xref:System.Net.Http.HttpClient>servicestothemainprojectoftheBlazorWebAppbecausethecomponentisn't prerendered on the server.
618
+
*Ifprerenderingisn't required for a WebAssembly component that calls the web API, disable prerendering by following the guidance in <xref:blazor/components/prerender#disable-prerendering>. If you adopt this approach, you don'tneedtoadd<xref:System.Net.Http.HttpClient>servicestothemainprojectoftheBlazorWebAppbecausethecomponentisn't prerendered on the server.
619
619
620
-
Formoreinformation, see [Client-sideservicesfailtoresolveduringprerendering](xref:blazor/components/render-modes#client-side-services-fail-to-resolve-during-prerendering).
Whenprerendering, componentsrendertwice: firststatically, theninteractively. Statedoesn't automatically flow from the prerendered component to the interactive one. If a component performs asynchronous initialization operations and renders different content for different states during initialization, such as a "Loading..." progress indicator, you may see a flicker when the component renders twice.
YoucanaddressthisbyflowingprerenderedstateusingthePersistentComponentStateAPI, whichthe `BlazorWebAppCallWebApi` and `BlazorWebAppCallWebApi_Weather` [sampleapps](#sample-apps) demonstrate. Whenthecomponentrendersinteractively, itcanrenderthesamewayusingthesamestate. However, theAPIdoesn't currently work with enhanced navigation, which you can work around by disabling enhanced navigation on links to the page (`data-enhanced-nav=false`). For more information, see the following resources:
YoucanaddressthisbyflowingprerenderedstateusingthePersistentComponentStateAPI, whichthe `BlazorWebAppCallWebApi` and `BlazorWebAppCallWebApi_Weather` [sampleapps](#sample-apps) demonstrate. Whenthecomponentrendersinteractively, itcanrenderthesamewayusingthesamestate. However, theAPIdoesn't currently work with enhanced navigation, which you can work around by disabling enhanced navigation on links to the page (`data-enhanced-nav=false`). For more information, see the following resources:
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/cascading-values-and-parameters.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -290,7 +290,7 @@ Add a navigation link to the `DaleksMain` component in `NavMenu.razor`:
290
290
</div>
291
291
```
292
292
293
-
Because the <xref:Microsoft.AspNetCore.Components.CascadingValueSource%601>'s type in this example (`NotifyingDalek`) is a class type, you can meet virtually any state management feature specification requirement. However, subscriptions create overhead and reduce performance, so benchmark the performance of this approach in your app and compare it to other [state management approaches](xref:blazor/state-management) before adopting it in a production app with constrained processing and memory resources.
293
+
Because the <xref:Microsoft.AspNetCore.Components.CascadingValueSource%601>'s type in this example (`NotifyingDalek`) is a class type, you can meet virtually any state management feature specification requirement. However, subscriptions create overhead and reduce performance, so benchmark the performance of this approach in your app and compare it to other [state management approaches](xref:blazor/state-management/index) before adopting it in a production app with constrained processing and memory resources.
294
294
295
295
Any change in state (any property value change of the class) causes all subscribed components to rerender, regardless of which part of the state they use. **Avoid creating a single large class representing the entire global application state.** Instead, create granular classes and cascade them separately with specific subscriptions to cascading parameters, ensuring that only components subscribed to a specific portion of the application state are affected by changes.
296
296
@@ -517,7 +517,7 @@ Cascading parameters don't pass data across render mode boundaries:
517
517
518
518
* State crossing the boundary between static and interactive rendering must be serializable. Components are arbitrary objects that reference a vast chain of other objects, including the renderer, the DI container, and every DI service instance. You must explicitly cause state to be serialized from static SSR to make it available in subsequent interactively-rendered components. Two approaches are adopted:
519
519
* Via the Blazor framework, parameters passed across a static SSR to interactive rendering boundary are serialized automatically if they're JSON-serializable, or an error is thrown.
520
-
* State stored in [`PersistentComponentState`](xref:blazor/components/prerender#persist-prerendered-state) is serialized and recovered automatically if it's JSON-serializable, or an error is thrown.
520
+
* State stored in [Persistent Component State](xref:blazor/state-management/prerendered-state-persistence) is serialized and recovered automatically if it's JSON-serializable, or an error is thrown.
521
521
522
522
Cascading parameters aren't JSON-serializable because the typical usage patterns for cascading parameters are somewhat like DI services. There are often platform-specific variants of cascading parameters, so it would be unhelpful to developers if the framework stopped developers from having server-interactive-specific versions or WebAssembly-specific versions. Also, many cascading parameter values in general aren't serializable, so it would be impractical to update existing apps if you had to stop using all nonserializable cascading parameter values.
523
523
@@ -718,4 +718,4 @@ The following `ExampleTabSet` component uses the `TabSet` component, which conta
718
718
## Additional resources
719
719
720
720
*[Generic type support: Explicit generic types based on ancestor components](xref:blazor/components/generic-type-support#explicit-generic-types-based-on-ancestor-components)
721
-
*[State management: Factor out state preservation to a common provider](xref:blazor/state-management?pivots=server#factor-out-state-preservation-to-a-common-provider)
721
+
*[State management: Protected browser storage: Factor out state preservation to a common provider](xref:blazor/state-management/protected-browser-storage#factor-out-state-preservation-to-a-common-provider)
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/data-binding.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1043,7 +1043,7 @@ Prior to the release of .NET 7, two-way binding across components uses `get`/`se
1043
1043
1044
1044
:::moniker-end
1045
1045
1046
-
For an alternative approach suited to sharing data in memory and across components that aren't necessarily nested, see <xref:blazor/state-management>.
1046
+
For an alternative approach suited to sharing data in memory and across components that aren't necessarily nested, see <xref:blazor/state-management/index>.
*[Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
554
553
* Razor component lifecycle subjects that pertain to prerendering
*[Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
1069
1067
* Razor component lifecycle subjects that pertain to prerendering
*[Prerendering support with assembly lazy loading](xref:blazor/webassembly-lazy-load-assemblies#lazy-load-assemblies-in-a-hosted-blazor-webassembly-solution)
1327
1324
* Razor component lifecycle subjects that pertain to prerendering
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/lifecycle.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,7 +206,7 @@ Blazor apps that prerender their content on the server call <xref:Microsoft.AspN
206
206
207
207
:::moniker range=">= aspnetcore-8.0"
208
208
209
-
To prevent developer code in <xref:Microsoft.AspNetCore.Components.ComponentBase.OnInitializedAsync%2A> from running twice when prerendering, see the [Stateful reconnection after prerendering](#stateful-reconnection-after-prerendering) section. The content in the section focuses on Blazor Web Apps and stateful SignalR *reconnection*. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/components/prerender#persist-prerendered-state>.
209
+
To prevent developer code in <xref:Microsoft.AspNetCore.Components.ComponentBase.OnInitializedAsync%2A> from running twice when prerendering, see the [Stateful reconnection after prerendering](#stateful-reconnection-after-prerendering) section. The content in the section focuses on Blazor Web Apps and stateful SignalR *reconnection*. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/state-management/prerendered-state-persistence>.
210
210
211
211
:::moniker-end
212
212
@@ -722,7 +722,7 @@ By combining streaming rendering with persistent component state:
722
722
For more information, see the following resources:
@@ -795,7 +795,7 @@ For more information on the <xref:Microsoft.AspNetCore.Mvc.TagHelpers.ComponentT
795
795
796
796
:::moniker range=">= aspnetcore-8.0"
797
797
798
-
The content in this section focuses on Blazor Web Apps and stateful SignalR *reconnection*. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/components/prerender#persist-prerendered-state>.
798
+
The content in this section focuses on Blazor Web Apps and stateful SignalR *reconnection*. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/state-management/prerendered-state-persistence>.
0 commit comments