Skip to content

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

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

Merged
merged 10 commits into from
Jul 17, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 9, 2025

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>
@Copilot 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 Copilot AI requested a review from ilonatommy July 9, 2025 07:40
Copilot finished work on behalf of ilonatommy July 9, 2025 07:40
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy July 9, 2025 07:54
…dation

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
@Copilot Copilot AI requested a review from ilonatommy July 9, 2025 08:27
Copilot finished work on behalf of ilonatommy July 9, 2025 08:27
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
@ilonatommy
Copy link
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>
Copy link
Contributor Author

Copilot AI commented Jul 9, 2025

@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

Copilot finished work on behalf of ilonatommy July 9, 2025 12:31
@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
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>
Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

@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

Copilot finished work on behalf of ilonatommy July 15, 2025 08:07
@ilonatommy
Copy link
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>
Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

@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

Copilot finished work on behalf of ilonatommy July 15, 2025 08:21
Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

This should work.

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@Copilot Copilot AI requested a review from javiercn July 15, 2025 09:56
Copilot finished work on behalf of javiercn July 15, 2025 09:56
@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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy