Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

EditForm.OnValidSubmit called 4 times in rapid succession

$
0
0

We have one user this is happening with. They are using a ChromeBook. 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.");    try    {        SubmitEnabled = false;        // ...    }    finally    {        SubmitEnabled = true;    }}

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?

Update: MrC suggested it might be the DxButton. I looked at the html that generated and it's:

<button class="dxbl-btn dxbl-btn-primary dxbl-btn-standalone" id="save" type="submit"><span class="dxbl-btn-caption">Save Changes to Profile</span></button>

So I don't think DxButton is the issue.

Update: As requested, here's the relevant code from ExPageBase.

protected override async Task OnInitializedAsync(){    await base.OnInitializedAsync();    // This will:    // 1. Initialize Principal.    // 2. Assign the logged in user to the User property.    Principal = (await AuthenticationStateTask).User;    LoggerEx = await ScopedLoggerFactoryEx.GetLogger(GetType());    var user = await UserManager.GetUserAsync(Principal);    // when they login, we don't know it. And there are other minor cases where we don't know    // that these settings have change. And this is an incredibly lightweight call. So we always    // call this    if (SessionData.ShowAnything || !SessionData.DataInitialized)        SessionData.Reset(user);    if (user == null)    {        SessionData.AnonymousUser ??= AppUser.CreateAnonymous();        User = SessionData.AnonymousUser;    }    else        User = user;}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>