Skip to content

Commit 3959210

Browse files
committed
Fix POST with re-execution.
1 parent d03bf14 commit 3959210

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ await _renderer.InitializeStandardComponentServicesAsync(
121121
try
122122
{
123123
var isBadRequest = false;
124-
quiesceTask = _renderer.DispatchSubmitEventAsync(result.HandlerName, out isBadRequest);
124+
quiesceTask = _renderer.DispatchSubmitEventAsync(result.HandlerName, out isBadRequest, isReExecuted);
125125
if (isBadRequest)
126126
{
127127
return;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal partial class EndpointHtmlRenderer
2222
private readonly Dictionary<(int ComponentId, int FrameIndex), string> _namedSubmitEventsByLocation = new();
2323
private readonly Dictionary<string, HashSet<(int ComponentId, int FrameIndex)>> _namedSubmitEventsByScopeQualifiedName = new(StringComparer.Ordinal);
2424

25-
internal Task DispatchSubmitEventAsync(string? handlerName, out bool isBadRequest)
25+
internal Task DispatchSubmitEventAsync(string? handlerName, out bool isBadRequest, bool isReExecuted = false)
2626
{
2727
if (string.IsNullOrEmpty(handlerName))
2828
{
@@ -34,6 +34,14 @@ internal Task DispatchSubmitEventAsync(string? handlerName, out bool isBadReques
3434

3535
if (!_namedSubmitEventsByScopeQualifiedName.TryGetValue(handlerName, out var locationsForName) || locationsForName.Count == 0)
3636
{
37+
if (isReExecuted)
38+
{
39+
// If we are re-executing, we do not expect to find a new form on the page we re-execute to.
40+
// This does not mean that the request is bad, we want the re-execution to succeed.
41+
isBadRequest = false;
42+
return Task.CompletedTask;
43+
}
44+
3745
// This may happen if you deploy an app update and someone still on the old page submits a form,
3846
// or if you're dynamically building the UI and the submitted form doesn't exist the next time
3947
// the page is rendered

src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ private void AssertNotFoundContentNotRendered(bool responseHasStarted)
149149
}
150150
}
151151

152-
153152
private void AssertUrlNotChanged(string expectedUrl) =>
154153
Browser.True(() => Browser.Url.Contains(expectedUrl), $"Expected URL to contain '{expectedUrl}', but found '{Browser.Url}'");
155154

@@ -274,7 +273,7 @@ public void NotFoundSetOnInitialization_ResponseStarted_CustomRouter_SSR(bool ha
274273

275274
if (hasReExecutionMiddleware)
276275
{
277-
AssertReExecutionPageRendered();
276+
AssertReExecutionPageRendered();
278277
}
279278
else
280279
{
@@ -372,7 +371,6 @@ public void NotFoundSetOnFormSubmit_ResponseStarted_SSR(bool hasReExecutionMiddl
372371
Navigate(testUrl);
373372
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
374373

375-
376374
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
377375
if (notFoundContentForRenderingProvided)
378376
{

0 commit comments

Comments
 (0)