Skip to content

Commit b416805

Browse files
committed
Fix early return condition.
1 parent cd5dffa commit b416805

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.AspNetCore.Components.Endpoints.Rendering;
55
using Microsoft.AspNetCore.Components.Rendering;
66
using Microsoft.AspNetCore.Components.RenderTree;
7-
using Microsoft.AspNetCore.Diagnostics;
87
using Microsoft.AspNetCore.Http;
98
using Microsoft.AspNetCore.WebUtilities;
109
using Microsoft.Extensions.DependencyInjection;
@@ -94,8 +93,6 @@ private async Task SetNotFoundResponseAsync(string baseUri)
9493
_httpContext.Response.StatusCode = StatusCodes.Status404NotFound;
9594
_httpContext.Response.ContentType = null;
9695
}
97-
var statusCodeFeature = new StatusCodeReExecuteFeature();
98-
_httpContext.Features.Set<IStatusCodeReExecuteFeature>(statusCodeFeature);
9996
SignalRendererToFinishRendering();
10097
}
10198

0 commit comments

Comments
 (0)