Browse Source

Prevent double-submit in mud Create/Update Entity actions

Saas tenant create modal (and other mud CRUD pages) duplicated rows when
the user double-clicked Save: the second click hit AppService.CreateAsync
before the first response had returned.

Add IsCreating / IsUpdating gates to AbpMudCrudPageBase so concurrent
calls return immediately. Wrap the body in try/finally and trigger
StateHasChanged so any UI bindings to these flags reflect the busy state.
pull/25393/head
maliming 3 weeks ago
parent
commit
6f9cb01ef4
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 29
      framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs

29
framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs

@ -203,6 +203,9 @@ public abstract class AbpMudCrudPageBase<
protected MudDialog? _createDialog;
protected MudDialog? _editDialog;
protected bool IsCreating { get; set; }
protected bool IsUpdating { get; set; }
protected virtual DialogOptions CreateDialogOptions => new DialogOptions
{
MaxWidth = MaxWidth.Medium,
@ -452,8 +455,16 @@ public abstract class AbpMudCrudPageBase<
protected virtual async Task CreateEntityAsync()
{
if (IsCreating)
{
return;
}
try
{
IsCreating = true;
await InvokeAsync(StateHasChanged);
var isValid = true;
if (CreateFormRef != null)
{
@ -476,6 +487,11 @@ public abstract class AbpMudCrudPageBase<
{
await HandleErrorAsync(ex);
}
finally
{
IsCreating = false;
await InvokeAsync(StateHasChanged);
}
}
protected virtual Task OnCreatingEntityAsync()
@ -497,8 +513,16 @@ public abstract class AbpMudCrudPageBase<
protected virtual async Task UpdateEntityAsync()
{
if (IsUpdating)
{
return;
}
try
{
IsUpdating = true;
await InvokeAsync(StateHasChanged);
var isValid = true;
if (EditFormRef != null)
{
@ -521,6 +545,11 @@ public abstract class AbpMudCrudPageBase<
{
await HandleErrorAsync(ex);
}
finally
{
IsUpdating = false;
await InvokeAsync(StateHasChanged);
}
}
protected virtual Task OnUpdatingEntityAsync()

Loading…
Cancel
Save