EditForm.OnValidSubmit called 4 times in rapid succession

David Thielen 2,956 Reputation points
2024-07-03T18:31:54.1666667+00:00

Hi all;

We have one user this is happening with. We cannot reproduce it and it is not happening to any others. And it has happened to them twice out of 8 uses of the relevant page. Needless to say, I can't create a MVE because we can't reproduce it.

The page (relevant parts) is:

@page "/Account/UserProfile"
@attribute [Authorize]
@inherits ExPageBase
@implements IDisposable

<EditForm EditContext="_editContext" OnValidSubmit="HandleValidSubmitAsync" OnInvalidSubmit="HandleInvalidSubmitAsync" Context="EditFormContext">
    <DataAnnotationsValidator />
    <CustomValidation @ref="_customValidation" />
    <DxFormLayout>
        <DxFormLayoutItem ColSpanMd="12">
            <DxButton Text="Save Changes to Profile"
                      Id="save"
                      SubmitFormOnClick="true"
                      Enabled="SubmitEnabled"
                      RenderStyle="@ButtonRenderStyle.Primary" />
        </DxFormLayoutItem>
    </DxFormLayout>
</EditForm>

private async Task HandleValidSubmitAsync(EditContext editContext)
{
    if (LoggerEx.IsEnabled(LogLevel.Debug))
        LoggerEx.LogDebug($"User {User.Email} is updating their account.");

And the log shows:

Debug 16:09:12.139 [dw0sdwk00065I]-[user@mail.com] LouisHowe.web.Pages.Account.UserAccountProfile - User user@mail.com is updating their account.
Debug 16:09:12.150 [dw0sdwk00065I]-[user@mail.com] LouisHowe.web.Pages.Account.UserAccountProfile - User user@mail.com is updating their account.
Debug 16:09:12.160 [dw0sdwk00065I]-[user@mail.com] LouisHowe.web.Pages.Account.UserAccountProfile - User user@mail.com is updating their account.
Debug 16:09:14.435 [dw0sdwk00065I]-[user@mail.com] LouisHowe.web.Pages.Account.UserAccountProfile - User user@mail.com is updating their account.

The user says they clicked submit once. We've tried everything we can to reproduce it with no luck.

When this happens it is causing an exception in the EntityFramework save of the data due to duplicates in collections of the user model object. This makes me think somehow the PageModel object is the same for all these calls, and that is then updating the underlying EF model object with the same collection items on each call, thereby placing duplicates in it.

How could the OnValidSubmit be called repeatedly in quick succession?

thanks - dave

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,536 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.