Skip to content

Commit 380ed10

Browse files
committed
[Pre5] Blazor What's New updates
1 parent 99d6b83 commit 380ed10

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

aspnetcore/blazor/call-web-api.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,6 @@ Calling <xref:System.Net.Http.HttpContent.ReadAsStreamAsync%2A?displayProperty=n
12891289
12901290
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
12911291
1292-
<!-- UPDATE 10.0 - Tracking on https://github.com/dotnet/runtime/issues/97449
1293-
12941292
To opt-out of response streaming globally, use either of the following approaches:
12951293
12961294
* Add the `<WasmEnableStreamingResponse>` property to the project file with a value of `false`:
@@ -1301,12 +1299,6 @@ To opt-out of response streaming globally, use either of the following approache
13011299
13021300
* Set the `DOTNET_WASM_ENABLE_STREAMING_RESPONSE` environment variable to `false` or `0`.
13031301
1304-
............. AND REMOVE THE NEXT LINE .............
1305-
1306-
-->
1307-
1308-
To opt-out of response streaming globally, set the `DOTNET_WASM_ENABLE_STREAMING_RESPONSE` environment variable to `false` or `0`.
1309-
13101302
To opt-out of response streaming for an individual request, set <xref:Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions.SetBrowserResponseStreamingEnabled%2A> to `false` on the <xref:System.Net.Http.HttpRequestMessage> (`request` in the following example):
13111303
13121304
```csharp

aspnetcore/blazor/fundamentals/routing.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -730,35 +730,30 @@ When a component is rendered statically (static SSR) and `NavigationManager.NotF
730730
}
731731
```
732732

733-
Two approaches for providing Not Found content for global interactive rendering:
733+
To provide Not Found content for global interactive rendering, use a Not Found page (Razor component).
734734

735-
* Use a Not Found page (Razor component).
736-
* Specify Not Found content in the [`Router` component's](xref:blazor/fundamentals/routing#route-templates) <xref:Microsoft.AspNetCore.Components.Routing.Router.NotFound%2A> property (`<NotFound>...</NotFound>` markup or by setting the `NotFound` parameter to a render fragment in C# code).
737-
738-
The following example uses a Not Found page (`NotFoundPage` component) to render Not Found content.
739-
740-
`NotFoundPage.razor`:
735+
`NotFound.razor`:
741736

742737
```razor
743738
<h1>Not Found</h1>
744739
745740
<p>Sorry! Nothing to show.</p>
746741
```
747742

748-
Specify the `NotFoundPage` component to the `Router` component in `Routes.razor`. You might need to specify the component's namespace with an [`@using`](xref:mvc/views/razor#using) directive either at the top of the `Routes.razor` file or in an [`_Imports.razor` file](xref:blazor/components/index#component-name-class-name-and-namespace).
743+
Assign the `NotFound` component to the router's `NotFoundPage` parameter. `NotFoundPage` supports routing that can be used across re-execution middleware, including non-Blazor middleware. If the `NotFound` render fragment is defined together with `NotFoundPage`, the page has higher priority.
744+
745+
In the following example, the preceding `NotFound` component is present in the app's `Pages` folder and passed to the `NotFoundPage` parameter:
749746

750747
```razor
751-
<Router ...>
752-
<Found ...>
753-
...
748+
<Router AppAssembly="@typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
749+
<Found Context="routeData">
750+
<RouteView RouteData="@routeData" />
751+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
754752
</Found>
755-
<NotFound>
756-
<NotFoundPage />
757-
</NotFound>
758753
</Router>
759754
```
760755

761-
When a component is rendered with a global interactive render mode, calling `NotFound` signals the Blazor router to render Not Found content, which is the `NotFoundPage` component:
756+
When a component is rendered with a global interactive render mode, calling `NotFound` signals the Blazor router to render the `NotFound` component:
762757

763758
```razor
764759
@page "/render-not-found-interactive"

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ In prior Blazor releases, response streaming for <xref:System.Net.Http.HttpClien
110110

111111
This is a breaking change because calling <xref:System.Net.Http.HttpContent.ReadAsStreamAsync%2A?displayProperty=nameWithType> for an <xref:System.Net.Http.HttpResponseMessage.Content%2A?displayProperty=nameWithType> (`response.Content.ReadAsStreamAsync()`) returns a `BrowserHttpReadStream` and no longer a <xref:System.IO.MemoryStream>. `BrowserHttpReadStream` doesn't support synchronous operations, such as `Stream.Read(Span<Byte>)`. If your code uses synchronous operations, you can opt-out of response streaming or copy the <xref:System.IO.Stream> into a <xref:System.IO.MemoryStream> yourself.
112112

113-
<!-- UNCOMMENT FOR PREVIEW 5 ...
114-
Waiting on https://github.com/dotnet/runtime/issues/97449
115-
... and update the Call web API article Line 983
116-
117113
To opt-out of response streaming globally, use either of the following approaches:
118114

119115
* Add the `<WasmEnableStreamingResponse>` property to the project file with a value of `false`:
@@ -124,12 +120,6 @@ To opt-out of response streaming globally, use either of the following approache
124120

125121
* Set the `DOTNET_WASM_ENABLE_STREAMING_RESPONSE` environment variable to `false` or `0`.
126122

127-
............. AND REMOVE THE NEXT LINE .............
128-
129-
-->
130-
131-
To opt-out of response streaming globally, set the `DOTNET_WASM_ENABLE_STREAMING_RESPONSE` environment variable to `false` or `0`.
132-
133123
To opt-out of response streaming for an individual request, set <xref:Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions.SetBrowserResponseStreamingEnabled%2A> to `false` on the <xref:System.Net.Http.HttpRequestMessage> (`requestMessage` in the following example):
134124

135125
```csharp
@@ -387,8 +377,6 @@ Calling <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A?di
387377

388378
Code that relied on <xref:Microsoft.AspNetCore.Components.NavigationException> being thrown should be updated. For example, in the default Blazor Identity UI, the `IdentityRedirectManager` previously threw an <xref:System.InvalidOperationException> after calling `RedirectTo` to ensure it wasn't invoked during interactive rendering. This exception and the [`[DoesNotReturn]` attributes](xref:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute) should now be removed.
389379

390-
<!-- HOLD FOR PREVIEW 5
391-
392380
To revert to the previous behavior of throwing a <xref:Microsoft.AspNetCore.Components.NavigationException>, set the following <xref:System.AppContext> switch:
393381

394382
```csharp
@@ -397,8 +385,6 @@ AppContext.SetSwitch(
397385
isEnabled: true);
398386
```
399387

400-
-->
401-
402388
### Not Found responses using `NavigationManager` for static SSR and global interactive rendering
403389

404390
The <xref:Microsoft.AspNetCore.Components.NavigationManager> now includes a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering:
@@ -412,3 +398,21 @@ Per-page/component rendering support is planned for Preview 5 in June, 2025.
412398
You can use the `NavigationManager.OnNotFound` event for notifications when `NotFound` is invoked.
413399

414400
For more information and examples, see <xref:blazor/fundamentals/routing?view=aspnetcore-10.0#not-found-responses>.
401+
402+
### Blazor router has a `NotFoundPage` parameter
403+
404+
Rendering content after triggering the `NavigationManager.NotFound` method can be now handled by passing a parameter with a component type to the router. This is now recommended over using the `NotFound` render fragment because `NotFoundPage` supports routing that can be used across re-execution middleware, including non-Blazor middleware. If the `NotFound` render fragment is defined together with `NotFoundPage`, the page has higher priority.
405+
406+
In the following example, a `NotFound` component is present in the app's `Pages` folder and passed to the `NotFoundPage` parameter. The `NotFound` page takes priority over the content in the `NotFound` fragment.
407+
408+
```razor
409+
<Router AppAssembly="@typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
410+
<Found Context="routeData">
411+
<RouteView RouteData="@routeData" />
412+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
413+
</Found>
414+
<NotFound>This content is ignored because 'NotFoundPage' is defined.</NotFound>
415+
</Router>
416+
```
417+
418+
For more information, see <xref:blazor/fundamentals/routing#not-found-responses>.

0 commit comments

Comments
 (0)