-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NotFoundPage
to Router
#60970
base: main
Are you sure you want to change the base?
Add NotFoundPage
to Router
#60970
Conversation
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs
Outdated
Show resolved
Hide resolved
src/Components/test/testassets/Components.WasmMinimal/Routes.razor
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
I think we will also want to update the project templates to use this feature.
In addition to it, I think there's another scenario we want to enable here which is to make sure that it works with UseStatusCodeWithReexecute
UseStatusCodeWithReexecute
allows the app to render a page after a 404 has been set somewhere. We want that to also be possible with a Component page
I did something similar for handling errors a couple releases back. This is the PR with the change for reference #50550
- I suspect we will need to do something similar here.
/cc: @danroth27
...ectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Pages/WeatherDetails.razor
Outdated
Show resolved
Hide resolved
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs
Outdated
Show resolved
Hide resolved
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesExtensions.cs
Show resolved
Hide resolved
src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs
Outdated
Show resolved
Hide resolved
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs
Outdated
Show resolved
Hide resolved
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs
Outdated
Show resolved
Hide resolved
src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Prerendering.cs
Outdated
Show resolved
Hide resolved
@@ -146,6 +148,7 @@ internal async ValueTask<PrerenderedComponentHtmlContent> RenderEndpointComponen | |||
{ | |||
var component = BeginRenderingComponent(rootComponentType, parameters); | |||
var result = new PrerenderedComponentHtmlContent(Dispatcher, component); | |||
stopAddingTasks = httpContext.Response.StatusCode == StatusCodes.Status404NotFound && _hasStatusCodePage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if we just remove httpContext.Response.StatusCode == StatusCodes.Status404NotFound
and use only _hasStatusCodePage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works but before doing so, I would like to clear the situation about re-executing what was not intended to re-execute see test.
{ | ||
_isHandlingErrors = isErrorHandler; | ||
if (IsProgressivelyEnhancedNavigation(httpContext.Request)) | ||
_hasStatusCodePage = hasStatusCodePage; | ||
bool avoidEditingHeaders = hasStatusCodePage && httpContext.Response.StatusCode == StatusCodes.Status404NotFound; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this effectively disabling streaming renders in 404 responses? Is there a reason for us to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we start writing the response, we are effectively blocking the middleware's re-execution, a similar case to
#60970 (comment)
but with context.Response.HasStarted
.
Description
NotFoundPage
parameter that can be used to customize the view of page rendered onNotFoundEvent
._notFound
was done, so we use redirection to a hardcodednot-found
page.NotFound
page.app.UseStatusCodePagesWithReExecute("/reexecution-path", createScopeForErrors: true);
Fixes #58815