Nested dialogs do not fully work

If you have nested dialogs (component A opens dialog A1, and dialog A1 opens dialog A2), the code won't continue when returning from DialogService.OpenAsync for dialog A1.

The problem seems to be that DialogService.OpenAsync overwrites the TaskCompletionSource in the protected field tcs:

public Task<dynamic> OpenAsync<T>(string title, Dictionary<string, object> parameters = null, DialogOptions options = null)
        where T : ComponentBase
        {
            this.tcs = new TaskCompletionSource<object>();
            this.OpenDialog<T>(title, parameters, options);
            return this.tcs.Task;
        }

so when two OpenAsync calls are nested, after returning from OpenDialog, only the latest call
continues executing the code properly. The previous one does not continue.

Probably chaning the tcs to be a stack or a list will fix the problem

1 Like

It will be fixed in the upcoming update of Radzen.Blazor.

1 Like

Thank you Vladimir. It works great now!

I am not sure that it works. Take a look at my code
This is Client Side

This opens the first dialog

     var objAsync = await DialogService.OpenAsync<ContactCreate>(
                "Edit Contact",
                new Dictionary<string, object> {{"Contact", contactToEdit}});
          
     if (!(objAsync is Contact contactToUpdate))
     {
                return; // maybe canceled edit then objAsync has the value true
     }

Then in the Edit Contact I ask this question

 private async Task InactivateContactButtonClicked()
 {
        if (await DialogService.Confirm($"Setting a contact inactive will also remove all reports for that contact. ", "Inactivate Contact?") == false)
        {
            return;
        }
        Contact.Active = false;
        DialogService.Close(Contact);
  }

The edit dialog closes but the code that called the edit dialog are never called.

This code path works

 private async Task HandleValidSubmit()
    {
        _emailValidator.ClearErrors();

        // only check if this is a new contact
        if(Contact.Id == 0 && !string.IsNullOrEmpty(Contact.Email))
        {
            var emailExist = await ContactService.ContactEmailExist(Contact.CustomerId, Contact.Email);
            if (emailExist)
            {
                var errors = new Dictionary<string, List<string>>
                {
                    {nameof(Contact.Email), new List<string> {"Email already exist"}}
                };
                _emailValidator.DisplayErrors(errors);
                return;
            }
        }

        DialogService.Close(Contact);
    }