Skip to content

Support NotFound content rendering for a custom Router #62635

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Jul 9, 2025

This PR:

  • Removes support for NotFound fragment - it cannot be rendered using NavigationManager.NotFound(). UPDATE DOCS
  • Fixes issues with raising NotFound event after async operations.
  • Adds support for raising NotFound event without blazor default Router component.

Implementation description

  • Moves handling 404 signal from endpoint renderer to the endpoint invoker.
  • Refactors one SetNotFoundResponseAsync with httpContext.Response.HasStarted condition into 2 separate methods that are called before and after response started, if 404 event was triggered.
  • Communicates the the renderer that Router handled rendering of NotFoundPage by setting the Path in NotFoundEventArgs. If that property is not set, router treats the request as not handled, cleans the response and avoids flushing in order to allow re-execution middleware act.
  • Clean up tests and apply changes from Endpoint renderer waits for quiescence with stopping the rendering #62524 to support testing triggering 404 after async operation.

Fixes #62367, Fixes #62469, Fixes #62153

@ilonatommy ilonatommy added this to the 10.0-preview7 milestone Jul 9, 2025
@ilonatommy ilonatommy self-assigned this Jul 9, 2025
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Jul 9, 2025
@ilonatommy ilonatommy marked this pull request as ready for review July 16, 2025 07:23
@Copilot Copilot AI review requested due to automatic review settings July 16, 2025 07:23
@ilonatommy ilonatommy requested a review from a team as a code owner July 16, 2025 07:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the NotFound event handling in Blazor components to better support custom routers and fix issues with async operations. The main changes include removing the NotFound fragment support, moving 404 handling from the endpoint renderer to the endpoint invoker, and improving the communication between routers and renderers about NotFound event handling.

Key Changes:

  • Moves NotFound event handling from endpoint renderer to endpoint invoker for better async operation support
  • Refactors NotFoundEventArgs to use a settable Path property to indicate router handling
  • Updates test infrastructure to better test async NotFound scenarios and custom router behavior

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
NotFoundEventArgs.cs Converts constructor parameter to settable property for router communication
Router.cs Updates to set Path property when handling NotFound events
NavigationManager.cs Simplifies NotFound event triggering with reusable event args
RazorComponentEndpointInvoker.cs Moves NotFound handling logic from renderer to invoker
EndpointHtmlRenderer.cs Refactors NotFound response handling into separate methods
CustomRouter.cs Adds new custom router implementation for testing
Test files Updates test infrastructure and parameter names for better async testing

@ilonatommy ilonatommy enabled auto-merge (squash) July 17, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
2 participants