Skip to content

Add validation to Router component to prevent both NotFound and NotFoundPage being set#62625

Merged
ilonatommy merged 10 commits into
mainfrom
copilot/fix-62409
Jul 17, 2025
Merged

Add validation to Router component to prevent both NotFound and NotFoundPage being set#62625
ilonatommy merged 10 commits into
mainfrom
copilot/fix-62409

Conversation

Copilot AI commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

In this PR:

  • Add nullability operator in type for Router.NotFoundPage
    public Type NotFoundPage { get; set; } -> public Type? NotFoundPage { get; set; }
  • Mark NotFound render fragment in Router as deprecated.
  • When both: NotFound and NotFoundPage are defined, log a warning. Do it in Router.SetParametersAsync in if (NotFoundPage != null) condition. Use the logger that is available there, add a new method to private static partial class Log with warning level. In the warning message, underline that we prefer NotFoundPage to be used and that NotFound will be deprecated. We are disabling treating warnings as errors, so they have to be disabled in some places to fix the build.

Fixes: #62409

…neously

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Comment thread src/Components/Components/test/Routing/RouterTest.cs
Copilot AI changed the title [WIP] API proposal for Router.NotFoundPage Add validation to Router component to prevent both NotFound and NotFoundPage being set Jul 9, 2025
Copilot AI requested a review from ilonatommy July 9, 2025 07:40
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Comment thread src/Components/Components/src/Routing/Router.cs Outdated
…dation

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot AI requested a review from ilonatommy July 9, 2025 08:27
Comment thread src/Components/Components/src/Routing/Router.cs
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
@ilonatommy

Copy link
Copy Markdown
Member

@copilot, add one unit test to RouterTest.cs to check if the warning is produced correctly when we have both: NotFound fragment and NotFoundPage.

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>

Copilot AI commented Jul 9, 2025

Copy link
Copy Markdown
Contributor Author

@copilot, add one unit test to RouterTest.cs to check if the warning is produced correctly when we have both: NotFound fragment and NotFoundPage.

Added unit test LogsWarningWhenBothNotFoundAndNotFoundPageAreSet to RouterTest.cs that verifies the warning is logged correctly when both NotFound fragment and NotFoundPage are set. The test uses a custom TestLogger to capture the warning message and validates both the warning level and message content. Commit: aa54562

@ilonatommy ilonatommy added this to the 10.0-preview7 milestone Jul 11, 2025
@ilonatommy
ilonatommy marked this pull request as ready for review July 11, 2025 11:16
@ilonatommy
ilonatommy requested a review from a team as a code owner July 11, 2025 11:17
@ilonatommy

Copy link
Copy Markdown
Member

@copilot change the warning to throwing exception. Remove the warning pragma and change the LogsWarningWhenBothNotFoundAndNotFoundPageAreSet test to check if the exception got thrown.

…tion

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>

Copilot AI commented Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

@copilot change the warning to throwing exception. Remove the warning pragma and change the LogsWarningWhenBothNotFoundAndNotFoundPageAreSet test to check if the exception got thrown.

Done. Changed the warning to throwing an exception, removed the pragma warning disable from the validation logic, and updated the test ThrowsExceptionWhenBothNotFoundAndNotFoundPageAreSet to check for the exception instead of warning logs. All RouterTest tests are passing. Commit: c10c0d4

@ilonatommy

Copy link
Copy Markdown
Member

@copilot, in src\Components\test\testassets\Components.TestServer\RazorComponents\App.razor and src\Components\test\testassets\Components.WasmMinimal\Routes.razor that are assets for e2e tests, we have routers that have both: fragment and page passed. Change it to conditionally have either a router with NotFoundPage if NotFoundPageType is not null or a router with NotFound fragment without NotFoundPage if NotFoundPageType is null.

What's more, you did not finish the previous work:

  • remove #pragma warning disable CS0618 from Logger class, now it's not needed.
  • Why do we need TestLogger in Router test now, when we're checking for exception only, not for warnings? Clean it up.

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>

Copilot AI commented Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

@copilot, in src\Components\test\testassets\Components.TestServer\RazorComponents\App.razor and src\Components\test\testassets\Components.WasmMinimal\Routes.razor that are assets for e2e tests, we...

Done. Updated the test assets to conditionally use either NotFoundPage or NotFound fragment, removed the TestLogger implementation from RouterTest.cs since we're testing exceptions not warnings, and kept the necessary pragma warnings in the Log class for obsolete NotFound property usage. Commit: 0712e4c

@ilonatommy ilonatommy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should work.

Comment thread src/Components/Components/src/Routing/Router.cs Outdated
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@ilonatommy
ilonatommy merged commit 5f21e7c into main Jul 17, 2025
28 checks passed
@ilonatommy
ilonatommy deleted the copilot/fix-62409 branch July 17, 2025 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API proposal for Router.NotFoundPage

3 participants