Skip to content

Change priority of re-execution handling and allow router to stream NotFound contents #62178

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 6 commits into
base: main
Choose a base branch
from

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented May 30, 2025

Contributes to #62153.

Description

  • If re-execution middleware is set up together with the default Router, then in all the cases we should render NotFound fragment or NotFoundPage contents.
    We used to detect the status code in the rendering method to avoid flushing the response and hand-over the processing to re-execution middleware. We no longer do that and we removed nulling-out the response content type because it was done only to force re-execution middleware to process the request further.
  • In case we are streaming, we should allow Router to stream-in the NotFound contents.
    We used to inject JS-redirection into the page, which changed the url and introduced inconsistent behavior in comparison to non-streaming scenarios. If we avoid doing so and we ensure Router can stream, we are able to change the body of the page by streaming the NotFound fragment/page contents. We cannot change the DOM that is non-body, e.g. PageTitle because streaming cannot change the <head> section. Even if PageTitle.cs has [StreamRendering] attribute. From this reason, we are checking for DOM body contents in the streaming-related cases.
  • Adding Components.Shared.csproj was needed because we want the same components to be tested in global interactivity application (InteractivityTests.cs that is running Components.WasmMinimal.csproj) and per-component interactivity application (NoInteractivityTests.cs that is running Components.TestServer.csproj that is not loading WasmMinimal assembly). The neatest solution was to put the common components is an external razor library. We could also start loading WasmMinimal in non-interactive tests but I decided it makes it too messy.
  • I decided to break the rule of "no old tests should be removed" because old PageThatSetsNotFound and StreamingSetNotFound components were doing the same job as new PageThatSetsNotFound-non-streaming and PageThatSetsNotFound-streaming but the new version is doing it in a more unified way (both use the same child component that is also used in interactive version of that test).

@ilonatommy ilonatommy added this to the 10.0-preview6 milestone May 30, 2025
@ilonatommy ilonatommy self-assigned this May 30, 2025
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label May 30, 2025
@ilonatommy ilonatommy requested a review from javiercn May 30, 2025 13:26
@@ -127,36 +120,35 @@ private void Assert404ReExecuted() =>
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CanRenderNotFoundPageNoStreaming(bool useCustomNotFoundPage)
public void CanRenderNotFoundPage(bool streamingStarted)
Copy link
Member Author

Choose a reason for hiding this comment

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

This one covers the old:

  • CanRenderNotFoundPageNoStreaming(useCustomNotFoundPage: true),
  • CanRenderNotFoundPageWithStreaming(useCustomNotFoundPage: true) - we used to redirect to "not-found" route here, now the behavior is same as for no-streaming, so we can consolidate them.

[InlineData(false)]
public void CanRenderNotFoundPageWithStreaming(bool useCustomNotFoundPage)
[InlineData(true)]
public void DoesNotReExecuteIf404WasHandled(bool streamingStarted)
Copy link
Member Author

Choose a reason for hiding this comment

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

DoesNotReExecuteIf404WasHandled(streamingStarted: true) covers same content as CanRenderNotFoundPageWithStreaming(useCustomNotFoundPage: false).

DoesNotReExecuteIf404WasHandled(streamingStarted: false) covers same content as CanRenderNotFoundPageNoStreaming(useCustomNotFoundPage: false).

[InlineData(false, false)]
[InlineData(true, false)]
[InlineData(true, true)]
public void StatusCodePagesWithReExecution(bool streaming, bool responseStarted)
Copy link
Member Author

Choose a reason for hiding this comment

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

This test does not make sense now, as long as we have the default Router in blazor app, we won't re-execute. And that is the case of all the current test setups in E2E tests. To at least check if re-execution still gets rendered properly if a 404 was set externally (not by a NavigatorManager.NotFound call), StatusCodePagesWithReExecution tests were added.
The custom Router testing and handling will be a subject of the next PR.

@ilonatommy
Copy link
Member Author

ilonatommy commented May 30, 2025

image
it seems the tests cannot run rn, investigating

It might be connected to an issue with dotnet test, the previous attempt before dotnet mismatch finished with visible lack of test discovery:
image

@ilonatommy ilonatommy marked this pull request as ready for review June 2, 2025 07:42
@ilonatommy ilonatommy requested a review from a team as a code owner June 2, 2025 07:42
@ilonatommy ilonatommy added the * NO MERGE * Do not merge this PR as long as this label is present. label Jun 2, 2025
@ilonatommy
Copy link
Member Author

Adding no-merge until the tests won't be able to run fully. The PR can get an early review in the meantime.

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 * NO MERGE * Do not merge this PR as long as this label is present.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant