Skip to content

Commit cd190a7

Browse files
authored
Update prerendering cross-links (#35430)
1 parent 7c93ffd commit cd190a7

File tree

2 files changed

+83
-56
lines changed

2 files changed

+83
-56
lines changed

aspnetcore/blazor/components/prerender.md

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ The following counter component persists counter state during prerendering and r
106106
}
107107
```
108108

109-
<!-- HOLD until https://github.com/dotnet/aspnetcore/issues/61456
109+
<!-- UPDATE 10.0 - HOLD until https://github.com/dotnet/aspnetcore/issues/61456
110110
is resolved
111111
112112
```razor
@@ -123,11 +123,11 @@ The following counter component persists counter state during prerendering and r
123123
124124
@code {
125125
[SupplyParameterFromPersistentComponentState]
126-
public int CurrentCount { get; set; }
126+
public int? CurrentCount { get; set; }
127127
128128
protected override void OnInitialized()
129129
{
130-
if (CurrentCount == 0)
130+
if (CurrentCount is null)
131131
{
132132
CurrentCount = Random.Shared.Next(100);
133133
Logger.LogInformation("CurrentCount set to {Count}", CurrentCount);
@@ -373,15 +373,27 @@ Disabling enhanced navigation, which reduces performance but also avoids the pro
373373
Prerendering guidance is organized in the Blazor documentation by subject matter. The following links cover all of the prerendering guidance throughout the documentation set by subject:
374374

375375
* Fundamentals
376-
* <xref:Microsoft.AspNetCore.Components.Routing.Router.OnNavigateAsync> is executed *twice* when prerendering: [Handle asynchronous navigation events with `OnNavigateAsync`](xref:blazor/fundamentals/routing#handle-asynchronous-navigation-events-with-onnavigateasync)
377-
* [Startup: Control headers in C# code](xref:blazor/fundamentals/startup#control-headers-in-c-code)
376+
* [Overview: Client and server rendering concepts](xref:blazor/fundamentals/index#client-and-server-rendering-concepts)
377+
* Routing
378+
* [Static versus interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing)
379+
* [Route to components from multiple assemblies: Interactive routing](xref:blazor/fundamentals/routing#interactive-routing)
380+
* <xref:Microsoft.AspNetCore.Components.Routing.Router.OnNavigateAsync> is executed *twice* when prerendering: [Handle asynchronous navigation events with `OnNavigateAsync`](xref:blazor/fundamentals/routing#handle-asynchronous-navigation-events-with-onnavigateasync)
381+
* Startup
382+
* [Control headers in C# code](xref:blazor/fundamentals/startup#control-headers-in-c-code)
383+
* [Client-side loading indicators](xref:blazor/fundamentals/startup#client-side-loading-indicators)
384+
* [Environments: Read the environment client-side in a Blazor Web App](xref:blazor/fundamentals/environments#read-the-environment-client-side-in-a-blazor-web-app)
378385
* [Handle Errors: Prerendering](xref:blazor/fundamentals/handle-errors#prerendering)
379-
* [SignalR: Prerendered state size and SignalR message size limit](xref:blazor/fundamentals/signalr#prerendered-state-size-and-signalr-message-size-limit)
380-
381-
* [Render modes: Prerendering](xref:blazor/components/render-modes#prerendering)
386+
* SignalR
387+
* [Client-side rendering](xref:blazor/fundamentals/signalr#client-side-rendering)
388+
* [Prerendered state size and SignalR message size limit](xref:blazor/fundamentals/signalr#prerendered-state-size-and-signalr-message-size-limit)
382389

383390
* Components
384391
* [Control `<head>` content during prerendering](xref:blazor/components/control-head-content#control-head-content-during-prerendering)
392+
* Render modes
393+
* [Prerendering](xref:blazor/components/render-modes#prerendering)
394+
* [Detect rendering location, interactivity, and assigned render mode at runtime](xref:blazor/components/render-modes#detect-rendering-location-interactivity-and-assigned-render-mode-at-runtime)
395+
* [Client-side services fail to resolve during prerendering](xref:blazor/components/render-modes#client-side-services-fail-to-resolve-during-prerendering)
396+
* [Custom shorthand render modes](xref:blazor/components/render-modes#custom-shorthand-render-modes)
385397
* Razor component lifecycle subjects that pertain to prerendering
386398
* [Component initialization (`OnInitialized{Async}`)](xref:blazor/components/lifecycle#component-initialization-oninitializedasync)
387399
* [After component render (`OnAfterRender{Async}`)](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync)
@@ -391,9 +403,24 @@ Prerendering guidance is organized in the Blazor documentation by subject matter
391403
* [`QuickGrid` component sample app](xref:blazor/components/quickgrid#sample-app): The [**QuickGrid for Blazor** sample app](https://aspnet.github.io/quickgridsamples/) is hosted on GitHub Pages. The site loads fast thanks to static prerendering using the community-maintained [`BlazorWasmPrerendering.Build` GitHub project](https://github.com/jsakamoto/BlazorWasmPreRendering.Build).
392404
* [Prerendering when integrating components into Razor Pages and MVC apps](xref:blazor/components/integration)
393405

406+
* [Call a web API: Prerendered data](xref:blazor/call-web-api#prerendered-data)
407+
408+
* [File uploads: Upload files to a server with client-side rendering (CSR)](xref:blazor/file-uploads#upload-files-to-a-server-with-client-side-rendering-csr)
409+
410+
* [Globalization and localization: Location override using "Sensors" pane in developer tools](xref:blazor/globalization-localization#location-override-using-sensors-pane-in-developer-tools)
411+
394412
* Authentication and authorization
395413
* [Server-side threat mitigation: Cross-site scripting (XSS)](xref:blazor/security/interactive-server-side-rendering#cross-site-scripting-xss)
396-
* [Server-side unauthorized content display while prerendering with a custom `AuthenticationStateProvider`](xref:blazor/security/index#unauthorized-content-display-while-prerendering-with-a-custom-authenticationstateprovider)
397-
* [Blazor WebAssembly rendered component authentication with prerendering](xref:blazor/security/webassembly/additional-scenarios#prerendering-with-authentication)
414+
* Blazor server-side security overview
415+
* [Manage authentication state in Blazor Web Apps](xref:blazor/security/index#manage-authentication-state-in-blazor-web-apps)
416+
* [Unauthorized content display while prerendering with a custom `AuthenticationStateProvider`](xref:blazor/security/index#unauthorized-content-display-while-prerendering-with-a-custom-authenticationstateprovider)
417+
* [Blazor server-side additional scenarios: Reading tokens from `HttpContext`](xref:blazor/security/additional-scenarios#reading-tokens-from-httpcontext)
418+
* [Blazor WebAssembly overview: Prerendering support](xref:blazor/security/webassembly/index#prerendering-support)
419+
* Blazor WebAssembly additional scenarios
420+
* [Rendered component authentication with prerendering](xref:blazor/security/webassembly/additional-scenarios#prerendering-with-authentication)
421+
* [Secure a SignalR hub](xref:blazor/security/webassembly/additional-scenarios#secure-a-signalr-hub)
422+
* [Interactive server-side rendering: Cross-site scripting (XSS)](xref:blazor/security/interactive-server-side-rendering#cross-site-scripting-xss)
398423

399424
* [State management: Handle prerendering](xref:blazor/state-management#handle-prerendering): Besides the *Handle prerendering* section, several of the article's other sections include remarks on prerendering.
425+
426+
For .NET 7 or earlier, see [Blazor WebAssembly security additional scenarios: Prerendering with authentication](xref:blazor/security/webassembly/additional-scenarios?view=aspnetcore-7.0&preserve-view=true#prerendering-with-authentication). After viewing the content in this section, reset the documentation article version selector dropdown to the latest .NET release version to ensure that documentation pages load for the latest release on subsequent visits.

aspnetcore/blazor/components/render-modes.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,52 @@ The following example applies interactive server-side rendering (interactive SSR
209209

210210
Additional information on render mode propagation is provided in the [Render mode propagation](#render-mode-propagation) section later in this article. The [Static SSR pages in an interactive app](#static-ssr-pages-in-an-interactive-app) section shows how to use the preceding approach to adopt static SSR in an otherwise interactive app.
211211

212+
## Blazor documentation examples for Blazor Web Apps
213+
214+
When using a Blazor Web App, most of the Blazor documentation example components ***require*** interactivity to function and demonstrate the concepts covered by the articles. When you test an example component provided by an article, make sure that either the app adopts global interactivity or the component adopts an interactive render mode.
215+
216+
## Prerendering
217+
218+
*Prerendering* is the process of initially rendering page content on the server without enabling event handlers for rendered controls. The server outputs the HTML UI of the page as soon as possible in response to the initial request, which makes the app feel more responsive to users. Prerendering can also improve [Search Engine Optimization (SEO)](https://developer.mozilla.org/docs/Glossary/SEO) by rendering content for the initial HTTP response that search engines use to calculate page rank.
219+
220+
Prerendering is enabled by default for interactive components.
221+
222+
Internal navigation for interactive routing doesn't involve requesting new page content from the server. Therefore, prerendering doesn't occur for internal page requests, including for [enhanced navigation](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling). For more information, see [Static versus interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing), [Interactive routing and prerendering](xref:blazor/components/prerender#interactive-routing-and-prerendering), and [Enhanced navigation and form handling](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling).
223+
224+
<!-- UPDATE 10.0 Tracking https://github.com/dotnet/aspnetcore/issues/55635
225+
for .NET 10 work in this area. Update the following remark
226+
if changes are made to the framework. -->
227+
228+
Disabling prerendering using the following techniques only takes effect for top-level render modes. If a parent component specifies a render mode, the prerendering settings of its children are ignored. This behavior is under investigation for possible changes with the release of .NET 10 in November, 2025.
229+
230+
To disable prerendering for a *component instance*, pass the `prerender` flag with a value of `false` to the render mode:
231+
232+
* `<... @rendermode="new InteractiveServerRenderMode(prerender: false)" />`
233+
* `<... @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />`
234+
* `<... @rendermode="new InteractiveAutoRenderMode(prerender: false)" />`
235+
236+
To disable prerendering in a *component definition*:
237+
238+
* `@rendermode @(new InteractiveServerRenderMode(prerender: false))`
239+
* `@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))`
240+
* `@rendermode @(new InteractiveAutoRenderMode(prerender: false))`
241+
242+
To disable prerendering for the entire app, indicate the render mode at the highest-level interactive component in the app's component hierarchy that isn't a root component.
243+
244+
For apps based on the Blazor Web App project template, a render mode assigned to the entire app is specified where the `Routes` component is used in the `App` component (`Components/App.razor`). The following example sets the app's render mode to Interactive Server with prerendering disabled:
245+
246+
```razor
247+
<Routes @rendermode="new InteractiveServerRenderMode(prerender: false)" />
248+
```
249+
250+
Also, disable prerendering for the [`HeadOutlet` component](xref:blazor/components/control-head-content#headoutlet-component) in the `App` component:
251+
252+
```razor
253+
<HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" />
254+
```
255+
256+
Making a root component, such as the `App` component, interactive with the `@rendermode` directive at the top of the root component's definition file (`.razor`) isn't supported. Therefore, prerendering can't be disabled directly by the `App` component.
257+
212258
:::moniker range=">= aspnetcore-9.0"
213259

214260
## Detect rendering location, interactivity, and assigned render mode at runtime
@@ -306,52 +352,6 @@ In the preceding example:
306352

307353
:::moniker-end
308354

309-
## Blazor documentation examples for Blazor Web Apps
310-
311-
When using a Blazor Web App, most of the Blazor documentation example components ***require*** interactivity to function and demonstrate the concepts covered by the articles. When you test an example component provided by an article, make sure that either the app adopts global interactivity or the component adopts an interactive render mode.
312-
313-
## Prerendering
314-
315-
*Prerendering* is the process of initially rendering page content on the server without enabling event handlers for rendered controls. The server outputs the HTML UI of the page as soon as possible in response to the initial request, which makes the app feel more responsive to users. Prerendering can also improve [Search Engine Optimization (SEO)](https://developer.mozilla.org/docs/Glossary/SEO) by rendering content for the initial HTTP response that search engines use to calculate page rank.
316-
317-
Prerendering is enabled by default for interactive components.
318-
319-
Internal navigation for interactive routing doesn't involve requesting new page content from the server. Therefore, prerendering doesn't occur for internal page requests, including for [enhanced navigation](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling). For more information, see [Static versus interactive routing](xref:blazor/fundamentals/routing#static-versus-interactive-routing), [Interactive routing and prerendering](xref:blazor/components/prerender#interactive-routing-and-prerendering), and [Enhanced navigation and form handling](xref:blazor/fundamentals/routing#enhanced-navigation-and-form-handling).
320-
321-
<!-- UPDATE 10.0 Tracking https://github.com/dotnet/aspnetcore/issues/55635
322-
for .NET 10 work in this area. Update the following remark
323-
if changes are made to the framework. -->
324-
325-
Disabling prerendering using the following techniques only takes effect for top-level render modes. If a parent component specifies a render mode, the prerendering settings of its children are ignored. This behavior is under investigation for possible changes with the release of .NET 10 in November, 2025.
326-
327-
To disable prerendering for a *component instance*, pass the `prerender` flag with a value of `false` to the render mode:
328-
329-
* `<... @rendermode="new InteractiveServerRenderMode(prerender: false)" />`
330-
* `<... @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />`
331-
* `<... @rendermode="new InteractiveAutoRenderMode(prerender: false)" />`
332-
333-
To disable prerendering in a *component definition*:
334-
335-
* `@rendermode @(new InteractiveServerRenderMode(prerender: false))`
336-
* `@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))`
337-
* `@rendermode @(new InteractiveAutoRenderMode(prerender: false))`
338-
339-
To disable prerendering for the entire app, indicate the render mode at the highest-level interactive component in the app's component hierarchy that isn't a root component.
340-
341-
For apps based on the Blazor Web App project template, a render mode assigned to the entire app is specified where the `Routes` component is used in the `App` component (`Components/App.razor`). The following example sets the app's render mode to Interactive Server with prerendering disabled:
342-
343-
```razor
344-
<Routes @rendermode="new InteractiveServerRenderMode(prerender: false)" />
345-
```
346-
347-
Also, disable prerendering for the [`HeadOutlet` component](xref:blazor/components/control-head-content#headoutlet-component) in the `App` component:
348-
349-
```razor
350-
<HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" />
351-
```
352-
353-
Making a root component, such as the `App` component, interactive with the `@rendermode` directive at the top of the root component's definition file (`.razor`) isn't supported. Therefore, prerendering can't be disabled directly by the `App` component.
354-
355355
## Static server-side rendering (static SSR)
356356

357357
Components use static server-side rendering (static SSR). The component renders to the response stream and interactivity isn't enabled.

0 commit comments

Comments
 (0)