Skip to content

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Sep 26, 2025

Fixes dotnet/aspnetcore#63831.

Tested locally on the issue's reproduction. The change fixes hot reload actions after the re-execution with UseStatusCodePagesWithReExecute heppened.

Changes:

  • In case injection of the refresh script was skipped, log a message,

before:
image

after (404 does not log it after the fix, it's only to show how logging would be visible to the user):
image

  • Allow refresh script injection for 404 status codes. This PR's goal is to fix the reported issue. I do not fully understand the filtering mechanism and it's possible that it requires more changes than just adding 404 code. Dan's question is valid here and further changes might be discussed and submitted later.

  • Cover the filtering mechanism with corresponding unit tests. We used to test only 200 case. I replaced this test with injection OK / injection not OK tests.

@ilonatommy ilonatommy self-assigned this Sep 26, 2025
@ilonatommy ilonatommy requested a review from a team as a code owner September 26, 2025 15:26
@ilonatommy ilonatommy requested review from Copilot and removed request for a team September 26, 2025 15:26
@ilonatommy ilonatommy added Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch Area-Watch labels Sep 26, 2025
Copy link
Contributor

This PR is targeting main, which is now for .NET 11-facing work. If you intended to target .NET 10, either retarget this PR to release/10.0.1xx or make sure you backport the change to release/10.0.1xx after merging. See #50394 for more details.

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 allows the hot reload refresh script to be injected for 404 status codes in addition to the existing 200 and 500 codes. The change addresses an issue where the browser refresh functionality wasn't working for 404 pages during development.

Key changes:

  • Extended status code filtering to include 404 responses
  • Added debug logging when script injection is skipped
  • Improved test coverage with parameterized tests for both supported and unsupported scenarios

Reviewed Changes

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

File Description
src/BuiltInTools/BrowserRefresh/ResponseStreamWrapper.cs Updated status code filtering logic to include 404 and added logging for skipped injections
src/BuiltInTools/BrowserRefresh/BrowserRefreshMiddleware.cs Added new logging method for script injection skip events
test/Microsoft.AspNetCore.Watch.BrowserRefresh.Tests/BrowserRefreshMiddlewareTest.cs Replaced single test with comprehensive parameterized tests covering multiple status codes and content types

Copy link
Contributor

Thanks for your PR, @@ilonatommy.
To learn about the PR process and branching schedule of this repo, please take a look at the SDK PR Guide.

@lewing lewing requested a review from tmat September 26, 2025 15:52
response.Headers.Remove(HeaderNames.ContentEncoding);

_pipe = new Pipe();
var gzipStream = new GZipStream(_pipe.Reader.AsStream(leaveOpen: true), CompressionMode.Decompress, leaveOpen: true);
Copy link
Member

Choose a reason for hiding this comment

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

Not changed in the PR, but do we want to dispose this stream at some point?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could store it same way as _baseStream and use the existing disposal methods to clean up after it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Merging to fix it asap.

@ilonatommy ilonatommy merged commit 2ca3933 into dotnet:main Sep 29, 2025
31 checks passed
@javiercn
Copy link
Member

/backport to release/10.0.1xx

Copy link
Contributor

Started backporting to release/10.0.1xx: https://github.com/dotnet/sdk/actions/runs/18097996562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch Area-Watch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UseStatusCodePagesWithReExecute to not-found breaks hot reload

3 participants