@@ -39,6 +39,7 @@ private async Task RenderComponentCore(HttpContext context)
3939 {
4040 context . Response . ContentType = RazorComponentResultExecutor . DefaultContentType ;
4141 var isErrorHandler = context . Features . Get < IExceptionHandlerFeature > ( ) is not null ;
42+ var hasStatusCodePage = context . Features . Get < IStatusCodePagesFeature > ( ) is not null ;
4243 var isReExecuted = context . Features . Get < IStatusCodeReExecuteFeature > ( ) is not null ;
4344 if ( isErrorHandler )
4445 {
@@ -90,7 +91,6 @@ await _renderer.InitializeStandardComponentServicesAsync(
9091 await using var writer = new HttpResponseStreamWriter ( context . Response . Body , Encoding . UTF8 , defaultBufferSize , ArrayPool < byte > . Shared , ArrayPool < char > . Shared ) ;
9192 using var bufferWriter = new BufferedTextWriter ( writer ) ;
9293
93- int originalStatusCode = context . Response . StatusCode ;
9494 bool isErrorHandlerOrReExecuted = isErrorHandler || isReExecuted ;
9595
9696 // Note that we always use Static rendering mode for the top-level output from a RazorComponentResult,
@@ -102,13 +102,10 @@ await _renderer.InitializeStandardComponentServicesAsync(
102102 ParameterView . Empty ,
103103 waitForQuiescence : result . IsPost || isErrorHandlerOrReExecuted ) ;
104104
105- bool isReExecutionRequested = context . Features . Get < IStatusCodeReExecuteFeature > ( ) is not null ;
106- bool avoidStartingResponse = ! isReExecuted && isReExecutionRequested ;
105+ bool avoidStartingResponse = hasStatusCodePage && ! isReExecuted && context . Response . StatusCode == StatusCodes . Status404NotFound ;
107106 if ( avoidStartingResponse )
108107 {
109- // re-execution feature was set during rendering,
110- // we should finish early to avoid writing to the response
111- // and let the re-execution middleware take care of it
108+ // the request is going to be re-executed, we should avoid writing to the response
112109 return ;
113110 }
114111
0 commit comments