Skip to content

Commit 40a842f

Browse files
committed
[11.0 P4] Blazor What's New feature coverage
1 parent b4c712c commit 40a842f

6 files changed

Lines changed: 200 additions & 11 deletions

File tree

aspnetcore/blazor/components/virtualization.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,34 @@ The <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> com
274274

275275
:::moniker-end
276276

277+
:::moniker range=">= aspnetcore-11.0"
278+
279+
## Control viewport scroll position behavior when items are dynamically added
280+
281+
<!-- UPDATE 11.0 - API cross-links -->
282+
283+
Assign a `VirtualizeAnchorMode` value to the `AnchorMode` parameter to control how the viewport behaves at list edges when items are dynamically added:
284+
285+
* `None`: No edge pinning. The viewport stays at current scroll position regardless of item changes.
286+
* `Beginning`: Pins the viewport to the beginning of the list. When the user is at a scroll position near the top of the list and new items arrive at the beginning, the viewport stays at the top showing the newest items. For example, this pinning behavior is useful for a news feed user experience.
287+
* `End`: Pins the viewport to the end of the list. When the user is at a scroll position near the bottom of the list and new items arrive at the end, the viewport auto-scrolls to show them. If the user has scrolled away, auto-scroll disengages until they return to the bottom. For example, this pinning behavior is useful for a chat or logging user experience.
288+
289+
The following example pins the viewport to the beginning of a virtualized flight list:
290+
291+
```razor
292+
<div style="height:500px;overflow-y:scroll">
293+
<Virtualize Items="allFlights" Context="flight" AnchorMode="Beginning">
294+
<FlightSummary @key="flight.FlightId" Details="@flight.Summary" />
295+
</Virtualize>
296+
</div>
297+
```
298+
299+
Modes can be combined. For example, assigning `Beginning | End` pins both edges. Combining `None` with other modes is supported but doesn't change the combined value.
300+
301+
`Virtualize.ItemComparer` gets or sets a comparer used to detect whether items were prepended or appended when using class-typed items with an <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.ItemsProvider%2A> (for more information, see the [Item provider delegate](#item-provider-delegate) section). The comparer determines if the first loaded item changed between provider calls, which indicates items were inserted at the top. For records, the default comparer's value-equality behavior (`EqualityComparer{T}.Default`) works automatically. For an in-memory <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.Items%2A> assignment, an `ItemComparer` comparer isn't required because the component can detect prepends automatically.
302+
303+
:::moniker-end
304+
277305
## State changes
278306

279307
When making changes to items rendered by the <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component, call <xref:Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged%2A> to enqueue re-evaluation and rerendering of the component. For more information, see <xref:blazor/components/rendering>.

aspnetcore/blazor/debug.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,27 @@ Blazor Server: [`Microsoft.AspNetCore.Components.WebAssembly.Server`](https://ww
164164

165165
:::moniker-end
166166

167-
Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer): Development server for use when building Blazor apps. Calls <xref:Microsoft.AspNetCore.Builder.WebAssemblyNetDebugProxyAppBuilderExtensions.UseWebAssemblyDebugging%2A> internally to add middleware for debugging Blazor WebAssembly apps inside Chromium developer tools.
167+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
168+
169+
https://www.nuget.org/packages?q=Microsoft.AspNetCore.Components.Gateway
170+
171+
:::moniker range=">= aspnetcore-11.0"
172+
173+
Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.Gateway`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Gateway): A lightweight ASP.NET Core host for serving standalone Blazor WebAssembly apps during development and production.
174+
175+
:::moniker-end
176+
177+
:::moniker range="< aspnetcore-11.0"
178+
179+
-->
180+
181+
Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer): Development server for use when building Blazor WebAssembly apps. Calls <xref:Microsoft.AspNetCore.Builder.WebAssemblyNetDebugProxyAppBuilderExtensions.UseWebAssemblyDebugging%2A> internally to add middleware for debugging Blazor WebAssembly apps inside Chromium developer tools.
182+
183+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
184+
185+
:::moniker-end
186+
187+
-->
168188

169189
:::moniker range="< aspnetcore-8.0"
170190

aspnetcore/blazor/security/webassembly/standalone-with-identity/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,34 @@ A standalone Blazor WebAssembly frontend app demonstrates user authentication an
181181

182182
The app uses the following NuGet packages:
183183

184+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
185+
186+
https://www.nuget.org/packages?q=Microsoft.AspNetCore.Components.Gateway
187+
188+
:::moniker range=">= aspnetcore-11.0"
189+
190+
* [`Microsoft.AspNetCore.Components.WebAssembly.Authentication`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.Authentication)
191+
* [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Microsoft.Extensions.Http)
192+
* [`Microsoft.AspNetCore.Components.WebAssembly`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly)
193+
* [`Microsoft.AspNetCore.Components.Gateway`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Gateway)
194+
195+
:::moniker-end
196+
197+
:::moniker range="< aspnetcore-11.0"
198+
199+
-->
200+
184201
* [`Microsoft.AspNetCore.Components.WebAssembly.Authentication`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.Authentication)
185202
* [`Microsoft.Extensions.Http`](https://www.nuget.org/packages/Microsoft.Extensions.Http)
186203
* [`Microsoft.AspNetCore.Components.WebAssembly`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly)
187204
* [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer)
188205

206+
<!-- UPDATE 11.0 - Activate when the NuGet package is available.
207+
208+
:::moniker-end
209+
210+
-->
211+
189212
### Sample app code
190213

191214
The `Models` folder contains the app's models:

aspnetcore/blazor/state-management/server.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ To persist temporary data between HTTP requests during static server-side render
213213
`TempData`:
214214

215215
* Is available when <xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A> is called in the app's `Program` file.
216-
* Is provided as a cascading value with the [`[CascadingParameter]` attribute](xref:blazor/components/cascading-values-and-parameters#cascadingparameter-attribute).
216+
* Is provided as a cascading value with the [`[CascadingParameter]` attribute](xref:blazor/components/cascading-values-and-parameters#cascadingparameter-attribute) or the `[SupplyParameterFromTempData]` parameter attribute.
217217
* Is accessed by key (string).
218218
* Supports primitives, <xref:System.DateTime>, <xref:System.Guid>, enums, and collections (arrays, <xref:System.Collections.Generic.List%601>, <xref:System.Collections.Generic.Dictionary%602>).
219219
* Stores `object?` values, requiring runtime casting (example: `var message = TempData["Message"] as string`). IntelliSense and type checking aren't supported.
@@ -224,6 +224,16 @@ To persist temporary data between HTTP requests during static server-side render
224224
public ITempData? TempData { get; set; }
225225
```
226226

227+
When supplied to a parameter for simple read/write of a single value, use the `[SupplyParameterFromTempData]` attribute without or with a key (string):
228+
229+
```csharp
230+
[SupplyParameterFromTempData]
231+
public string? Message { get; set; }
232+
233+
[SupplyParameterFromTempData(Name = "flash_message")]
234+
public string? FlashMessage { get; set; }
235+
```
236+
227237
The `ITempData` interface provides the following methods for controlling value lifecycle:
228238

229239
* `Get`: Gets the value associated with the specified key and schedules the data for deletion.
@@ -286,15 +296,16 @@ Browsers enforce a 4 KB cookie size limit. `TempData` automatically uses <xref:M
286296

287297
In the following example, a form displays a message that's retained in `TempData` after the form is submitted (a new request).
288298

289-
`Pages/TempDataExample.razor`:
299+
`Pages/TempDataExample1.razor`:
290300

291301
```razor
292-
@page "/tempdata-example"
302+
@page "/tempdata-example-1"
293303
@inject NavigationManager NavigationManager
294304
295305
<p>@message</p>
296306
297-
<form @onsubmit="HandleSubmit">
307+
<form method="post" @formname="SetMessage" @onsubmit="Submit">
308+
<AntiforgeryToken />
298309
<button type="submit">Submit</button>
299310
</form>
300311
@@ -310,7 +321,7 @@ In the following example, a form displays a message that's retained in `TempData
310321
message = TempData?.Get("Message") as string ?? "No message";
311322
}
312323
313-
private void HandleSubmit()
324+
private void Submit()
314325
{
315326
TempData!["Message"] = "Form submitted successfully!";
316327
NavigationManager.NavigateTo("/tempdata-example", forceLoad: true);
@@ -346,6 +357,33 @@ protected override void OnInitialized()
346357
}
347358
```
348359

360+
Similar to the preceding example but when only simple read/write of a single value is required, the following example uses the `[SupplyParameterFromTempData]` attribute.
361+
362+
`Pages/TempDataExample2.razor`:
363+
364+
```razor
365+
@page "/tempdata-example-2"
366+
@inject NavigationManager NavigationManager
367+
368+
<p>@Message</p>
369+
370+
<form method="post" @formname="SetMessage" @onsubmit="Submit">
371+
<AntiforgeryToken />
372+
<button type="submit">Submit</button>
373+
</form>
374+
375+
@code {
376+
[SupplyParameterFromTempData]
377+
public string? Message { get; set; }
378+
379+
private void Submit()
380+
{
381+
Message = "Form submitted successfully!";
382+
NavigationManager.NavigateTo("/tempdata-example", forceLoad: true);
383+
}
384+
}
385+
```
386+
349387
### Permanent data persistence
350388

351389
:::moniker-end

aspnetcore/blazor/tooling.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,25 @@ For more information, see the following resources:
494494

495495
## Blazor project templates and template options
496496

497+
:::moniker range=">= aspnetcore-11.0"
498+
499+
* Blazor Web App project template: `blazor`
500+
* Standalone Blazor WebAssembly app project template: `blazorwasm`
501+
* [Service defaults library for Blazor WebAssembly apps](#service-defaults-library-for-blazor-webassembly-apps): `blazor-wasm-servicedefaults`
502+
503+
> [!NOTE]
504+
> The "Hosted" Blazor WebAssembly project template option isn't available in .NET 8 or later. To create a hosted Blazor WebAssembly app, a **Framework** option earlier than .NET 8 must be selected with the **ASP.NET Core Hosted** checkbox. However, we recommend a Blazor Web App for all new Blazor development in .NET 8 or later. For more information, see the following resources:
505+
>
506+
> * <xref:blazor/index#build-a-full-stack-web-app-with-blazor>
507+
> * <xref:aspnetcore-8#new-blazor-web-app-template>
508+
> * <xref:blazor/project-structure#blazor-web-app>
509+
> * <xref:migration/70-to-80#convert-a-hosted-blazor-webassembly-app-into-a-blazor-web-app>
510+
511+
:::moniker-end
512+
497513
The Blazor framework provides project templates for creating new apps. The templates are used to create new Blazor projects and solutions regardless of the tooling that you select for Blazor development (Visual Studio, Visual Studio Code, or the [.NET command-line interface (CLI)](/dotnet/core/tools/)):
498514

499-
:::moniker range=">= aspnetcore-8.0"
515+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0"
500516

501517
* Blazor Web App project template: `blazor`
502518
* Standalone Blazor WebAssembly app project template: `blazorwasm`
@@ -604,6 +620,32 @@ For more information on template options, see the following resources:
604620

605621
:::moniker-end
606622

623+
:::moniker range=">= aspnetcore-11.0"
624+
625+
## Service defaults library for Blazor WebAssembly apps
626+
627+
The `blazor-wasm-servicedefaults` project template creates a service default library for Blazor WebAssembly apps with .NET Aspire integration.
628+
629+
The template features:
630+
631+
* [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-dotnet) support: Logging, metrics, and tracing with standard OTLP exporter.
632+
* Service discovery integration via the [`Microsoft.Extensions.ServiceDiscovery` NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.ServiceDiscovery).
633+
* HTTP resilience using the standard resilience handler via the [`Microsoft.Extensions.Http.Resilience` NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Http.Resilience).
634+
635+
Example template usage with an output name of `BlazorSample.ServiceDefaults`:
636+
637+
```dotnetcli
638+
dotnet new blazor-wasm-servicedefaults -o BlazorSample.ServiceDefaults
639+
```
640+
641+
Reference the library from the Blazor WebAssembly client and make the following call in the app's `Program` file:
642+
643+
```csharp
644+
builder.AddBlazorClientServiceDefaults();
645+
```
646+
647+
:::moniker-end
648+
607649
## Additional resources
608650

609651
:::moniker range=">= aspnetcore-6.0"

aspnetcore/release-notes/aspnetcore-11/includes/blazor.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,52 @@ TempData is available when <xref:Microsoft.Extensions.DependencyInjection.RazorC
112112
public ITempData? TempData { get; set; }
113113
```
114114

115-
For more information, see <xref:blazor/state-management/server?view=aspnetcore-11.0#server-side-storage>.
115+
When supplied to a parameter for simple read/write of a single value, use the `[SupplyParameterFromTempData]` attribute:
116+
117+
```csharp
118+
[SupplyParameterFromTempData]
119+
public string? Message { get; set; }
120+
```
121+
122+
For more information, see <xref:blazor/state-management/server?view=aspnetcore-11.0#temporary-data-persistence>.
116123

117124
### New Blazor Web Worker template (`blazorwebworker`)
118125

119126
Blazor WebAssembly apps can perform heavy computing on the client, but doing so on the UI thread interferes with UI rendering and negatively affects the user experience. In .NET 10, we added an article with a sample app to make offloading heavy work from the UI thread to a Web Worker easier. For .NET 11, we've added the Blazor Web Worker project template (`blazorwebworker`), which provides infrastructure for running .NET code in a Web Worker in Blazor WebAssembly apps. For more information, see <xref:blazor/blazor-web-workers?view=aspnetcore-11.0>.
120127

121-
### `Virtualize` adapts to variable-height items at runtime
128+
### Virtualization enhancements
129+
130+
* The <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component no longer assumes every item has the same height. The component now adapts to measured item sizes at runtime, which reduces incorrect spacing and scrolling when item heights vary. These updates include an update to the default value of <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.OverscanCount%2A?displayProperty=nameWithType>, which was `3` in .NET 10 or earlier and now changes to `15` in .NET 11 or later. The change in default value increases the precision of average item height calculations.
131+
132+
For more information, see the *Item size* and *Overscan count* sections of <xref:blazor/components/virtualization?view=aspnetcore-11.0#item-size>.
133+
134+
* Use the new `AnchorMode` parameter to control how the viewport behaves at list edges when items are dynamically added:
135+
136+
* `None`: No edge pinning. The viewport stays at current scroll position regardless of item changes.
137+
* `Beginning`: Pins the viewport to the beginning of the list. For example, this pinning behavior is useful for a news feed user experience.
138+
* `End`: Pins the viewport to the end of the list. For example, this pinning behavior is useful for a chat or logging user experience.
139+
140+
In the following example, the virtualized content is pinned to the beginning of the list:
141+
142+
```razor
143+
<Virtualize AnchorMode="Beginning" ...>
144+
...
145+
</Virtualize>
146+
```
147+
148+
For more information, see <xref:blazor/components/virtualization?view=aspnetcore-11.0#control-viewport-scroll-position-behavior-when-items-are-dynamically-added>.
149+
150+
### New service defaults library project template for Blazor WebAssembly apps
151+
152+
The `blazor-wasm-servicedefaults` project template creates a service default library for Blazor WebAssembly apps with .NET Aspire integration. For more information, see <xref:blazor/tooling?view=aspnetcore-11.0#service-defaults-library-for-blazor-webassembly-apps>.
153+
154+
### New development server for Blazor WebAssembly apps
155+
156+
<!-- UPDATE 11.0 - Link to package when it's out.
157+
158+
[`Microsoft.AspNetCore.Components.Gateway`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Gateway)
159+
-->
122160

123-
The <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601> component no longer assumes every item has the same height. The component now adapts to measured item sizes at runtime, which reduces incorrect spacing and scrolling when item heights vary. These updates include an update to the default value of <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.OverscanCount%2A?displayProperty=nameWithType>, which was `3` in .NET 10 or earlier and now changes to `15` in .NET 11 or later. The change in default value increases the precision of average item height calculations.
161+
`Microsoft.AspNetCore.Components.Gateway` is a lightweight ASP.NET Core host that replaces [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer) for serving standalone Blazor WebAssembly applications during development and production.
124162

125-
For more information, see the *Item size* and *Overscan count* sections of <xref:blazor/components/virtualization?view=aspnetcore-11.0#item-size>.
163+
For more information, see [[Blazor] Replace DevServer with BlazorGateway for standalone WASM apps (`dotnet/aspnetcore` #65982)](https://github.com/dotnet/aspnetcore/pull/65982).

0 commit comments

Comments
 (0)