Skip to content

Commit f39fcdd

Browse files
authored
Merge pull request #35209 from dotnet/main
2 parents dd01bf8 + f0386af commit f39fcdd

File tree

8 files changed

+144
-118
lines changed

8 files changed

+144
-118
lines changed

aspnetcore/blazor/components/integration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ In the following example, the `{TYPE}` placeholder represents the type of data t
416416
@code {
417417
[SupplyParameterFromPersistentComponentState]
418418
public {TYPE} Data { get; set; }
419+
420+
protected override async Task OnInitializedAsync()
421+
{
422+
Data ??= await ...;
423+
}
419424
}
420425
```
421426

aspnetcore/blazor/components/lifecycle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ else
646646
647647
private async Task<string> LoadDataAsync()
648648
{
649-
await Task.Delay(10000);
649+
await Task.Delay(5000);
650650
return "Finished!";
651651
}
652652
}
@@ -701,7 +701,7 @@ else
701701
702702
private async Task<string> LoadDataAsync()
703703
{
704-
await Task.Delay(10000);
704+
await Task.Delay(5000);
705705
return "Finished!";
706706
}
707707

aspnetcore/blazor/components/prerender.md

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,55 @@ The following counter component example persists counter state during prerenderi
7979
8080
<h1>Prerendered Counter 2</h1>
8181
82+
<p role="status">Current count: @State?.CurrentCount</p>
83+
84+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
85+
86+
@code {
87+
[SupplyParameterFromPersistentComponentState]
88+
public CounterState? State { get; set; }
89+
90+
protected override void OnInitialized()
91+
{
92+
if (State is null)
93+
{
94+
State = new() { CurrentCount = Random.Shared.Next(100) };
95+
Logger.LogInformation("CurrentCount set to {Count}",
96+
State.CurrentCount);
97+
}
98+
else
99+
{
100+
Logger.LogInformation("CurrentCount restored to {Count}",
101+
State.CurrentCount);
102+
}
103+
}
104+
105+
private void IncrementCount()
106+
{
107+
if (State is not null)
108+
{
109+
State.CurrentCount++;
110+
}
111+
}
112+
113+
public class CounterState
114+
{
115+
public int CurrentCount { get; set; }
116+
}
117+
}
118+
```
119+
120+
<!-- HOLD until https://github.com/dotnet/aspnetcore/issues/61456
121+
is resolved
122+
123+
```razor
124+
@page "/prerendered-counter-2"
125+
@inject ILogger<PrerenderedCounter2> Logger
126+
127+
<PageTitle>Prerendered Counter 2</PageTitle>
128+
129+
<h1>Prerendered Counter 2</h1>
130+
82131
<p role="status">Current count: @CurrentCount</p>
83132
84133
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@@ -89,13 +138,31 @@ The following counter component example persists counter state during prerenderi
89138
90139
protected override void OnInitialized()
91140
{
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+
}
94150
}
95151
96152
private void IncrementCount() => CurrentCount++;
97153
}
98154
```
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.
161+
162+
> :::no-loc text="info: BlazorSample.Components.Pages.PrerenderedCounter2[0]":::
163+
> :::no-loc text=" CurrentCount set to 96":::
164+
> :::no-loc text="info: BlazorSample.Components.Pages.PrerenderedCounter2[0]":::
165+
> :::no-loc text=" CurrentCount restored to 96":::
99166
100167
In the following example that serializes state for multiple components of the same type:
101168

@@ -283,6 +350,16 @@ The following counter component example persists counter state during prerenderi
283350
}
284351
```
285352

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.
357+
358+
> :::no-loc text="info: BlazorSample.Components.Pages.PrerenderedCounter3[0]":::
359+
> :::no-loc text=" currentCount set to 96":::
360+
> :::no-loc text="info: BlazorSample.Components.Pages.PrerenderedCounter3[0]":::
361+
> :::no-loc text=" currentCount restored to 96":::
362+
286363
:::moniker-end
287364

288365
:::moniker range="< aspnetcore-10.0"
@@ -340,18 +417,18 @@ The following counter component example persists counter state during prerenderi
340417

341418
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/PrerenderedCounter2.razor":::
342419

343-
:::moniker-end
344-
345420
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.
346421

347422
> [!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.
349424
350425
> :::no-loc text="info: BlazorSample.Components.Pages.PrerenderedCounter2[0]":::
351426
> :::no-loc text=" currentCount set to 96":::
352427
> :::no-loc text="info: BlazorSample.Components.Pages.PrerenderedCounter2[0]":::
353428
> :::no-loc text=" currentCount restored to 96":::
354429
430+
:::moniker-end
431+
355432
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.
356433

357434
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.

aspnetcore/blazor/host-and-deploy/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ dotnet publish -c Release
4343

4444
Publishing the app triggers a [restore](/dotnet/core/tools/dotnet-restore) of the project's dependencies and [builds](/dotnet/core/tools/dotnet-build) the project before creating the assets for deployment. As part of the build process, unused methods and assemblies are removed to reduce app download size and load times.
4545

46-
Publish locations:
46+
## Default publish locations
4747

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

5050
* Blazor Web App: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish` folder, where the `{TARGET FRAMEWORK}` placeholder is the target framework. Deploy the contents of the `publish` folder to the host.
51-
* Standalone Blazor WebAssembly: The app is published into the `bin\Release\{TARGET FRAMEWORK}\browser-wasm\publish\` folder. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
51+
* Standalone Blazor WebAssembly: The app is published into the `bin/Release/{TARGET FRAMEWORK}/publish` or `bin/Release/{TARGET FRAMEWORK}/browser-wasm/publish` folder. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
5252

5353
:::moniker-end
5454

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

5757
* Blazor Server: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish` folder, where the `{TARGET FRAMEWORK}` placeholder is the target framework.. Deploy the contents of the `publish` folder to the host.
5858
* Blazor WebAssembly
59-
* Standalone: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` or `bin\Release\{TARGET FRAMEWORK}\browser-wasm\publish` folder, depending on the version of the SDK used to publish the app. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
60-
* Hosted: The client Blazor WebAssembly app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` folder of the server app, along with any other static web assets of the client app. Deploy the contents of the `publish` folder to the host.
59+
* Standalone: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish` or `bin/Release/{TARGET FRAMEWORK}/browser-wasm/publish` folder. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
60+
* Hosted: The server ASP.NET Core app and client Blazor WebAssembly app are published into the `/bin/Release/{TARGET FRAMEWORK}/publish` folder of the server app, along with any static web assets of the client app. Deploy the contents of the `publish` folder to the host.
6161

6262
:::moniker-end
6363

aspnetcore/blazor/host-and-deploy/webassembly/deployment-layout.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ This article explains how to enable hosted Blazor WebAssembly deployments in env
1717
> [!NOTE]
1818
> This guidance addresses environments that block clients from downloading and executing DLLs. In .NET 8 or later, Blazor uses the Webcil file format to address this problem. For more information, see <xref:blazor/host-and-deploy/webassembly/index?view=aspnetcore-8.0&preserve-view=true#webcil-packaging-format-for-net-assemblies>. Multipart bundling using the experimental NuGet package described by this article isn't supported for Blazor apps in .NET 8 or later. You can use the guidance in this article to create your own multipart bundling NuGet package for .NET 8 or later.
1919
20+
:::moniker range=">= aspnetcore-8.0"
21+
22+
Blazor WebAssembly apps require [dynamic-link libraries (DLLs)](/windows/win32/dlls/dynamic-link-libraries) to function, but some environments block clients from downloading and executing DLLs. Security products are often able to scan the content of files traversing the network and block or quarantine DLL files. This article describes one approach for enabling Blazor WebAssembly apps in these environments, where a multipart bundle file is created from the app's DLLs so that the DLLs can be downloaded together bypassing security restrictions.
23+
24+
::: moniker-end
25+
26+
:::moniker range="< aspnetcore-8.0"
27+
2028
Blazor WebAssembly apps require [dynamic-link libraries (DLLs)](/windows/win32/dlls/dynamic-link-libraries) to function, but some environments block clients from downloading and executing DLLs. In a subset of these environments, [changing the file name extension of DLL files (`.dll`)](xref:blazor/host-and-deploy/webassembly/index#change-the-file-name-extension-of-dll-files) is sufficient to bypass security restrictions, but security products are often able to scan the content of files traversing the network and block or quarantine DLL files. This article describes one approach for enabling Blazor WebAssembly apps in these environments, where a multipart bundle file is created from the app's DLLs so that the DLLs can be downloaded together bypassing security restrictions.
2129

30+
::: moniker-end
31+
2232
A hosted Blazor WebAssembly app can customize its published files and packaging of app DLLs using the following features:
2333

2434
* [JavaScript initializers](xref:blazor/js-interop/index#javascript-initializers) that allow customizing the Blazor boot process.

aspnetcore/blazor/host-and-deploy/webassembly/iis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This article explains how to host and deploy Blazor WebAssembly using [Internet
1616

1717
IIS is a capable static file server for Blazor apps. To configure IIS to host Blazor, see [Build a Static Website on IIS](/iis/manage/creating-websites/scenario-build-a-static-website-on-iis).
1818

19-
Published assets are created in the `/bin/Release/{TARGET FRAMEWORK}/publish` or `bin\Release\{TARGET FRAMEWORK}\browser-wasm\publish` folder, depending on which version of the SDK is used and where the `{TARGET FRAMEWORK}` placeholder is the target framework. Host the contents of the `publish` folder on the web server or hosting service.
19+
Published assets are created in the `/bin/Release/{TARGET FRAMEWORK}/publish` or `bin/Release/{TARGET FRAMEWORK}/browser-wasm/publish` folder, where the `{TARGET FRAMEWORK}` placeholder is the target framework. Host the contents of the `publish` folder on the web server or hosting service.
2020

2121
## `web.config` file
2222

@@ -50,7 +50,7 @@ To use a custom `web.config` file:
5050

5151
If the SDK's `web.config` generation or transformation during publish either doesn't move the file to published assets in the `publish` folder or modifies the custom configuration in your custom `web.config` file, use any of the following approaches as needed to take full control of the process:
5252

53-
* If the SDK doesn't generate the file, for example, in a standalone Blazor WebAssembly app at `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` or `bin\Release\{TARGET FRAMEWORK}\browser-wasm\publish`, depending on which version of the SDK is used and where the `{TARGET FRAMEWORK}` placeholder is the target framework, set the `<PublishIISAssets>` property to `true` in the project file (`.csproj`). Usually for standalone WebAssembly apps, this is the only required setting to move a custom `web.config` file and prevent transformation of the file by the SDK.
53+
* If the SDK doesn't generate the file, for example, in a standalone Blazor WebAssembly app at `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` or `bin/Release/{TARGET FRAMEWORK}/browser-wasm/publish`, where the `{TARGET FRAMEWORK}` placeholder is the target framework, set the `<PublishIISAssets>` property to `true` in the project file (`.csproj`). Usually for standalone WebAssembly apps, this is the only required setting to move a custom `web.config` file and prevent transformation of the file by the SDK.
5454

5555
```xml
5656
<PropertyGroup>

0 commit comments

Comments
 (0)