fluentui-blazor: fix: OnCompleted stops dialogues working in FluentInputFile

🐛 Bug Report

If you try to use dialogues within the OnCompleted task of a FluentInputFile component, the buttons within the dialogue do not respond.

💻 Repro or Code Sample

This assumes that <FluentDialogProvider /> is added within MainLayout.razor or App.razor.

@page "/sandbox"

<h3>
    @_message
</h3>

<FluentStack HorizontalGap="4">
    <FluentButton OnClick="ShowConfirmationAsync" Appearance="Appearance.Accent">
        Show Confirmation Directly
    </FluentButton>
    <FluentButton Id="btnUpload" Appearance="Appearance.Accent">
        Upload Then Confirm
    </FluentButton>
</FluentStack>

<FluentInputFile Class="h-fit w-full"
                 Multiple="false"
                 AnchorId="btnUpload"
                 Mode="InputFileMode.Stream"
                 MaximumFileSize="@(1024 * 1024 * 1024)"
                 DragDropZoneVisible="false"
                 OnCompleted="OnFileUploadedAsync" />

@code {
    private string _message = "Ready.";

    [Inject]
    private IDialogService Dialogue { get; init; }

    private async Task OnFileUploadedAsync(IEnumerable<FluentInputFileEventArgs> args)
    {
        await ShowConfirmationAsync();
    }

    private async Task ShowConfirmationAsync()
    {
        var dialogue = await Dialogue.ShowConfirmationAsync("Do you want to continue?");
        var result = await dialogue.Result;
        _message = result.Cancelled
            ? "Cancelled"
            : "Accepted";
    }
}

🤔 Expected Behavior

Whether the confirmation dialogue is shown via OnClick from FluentButton, or OnComplete from FluentInputFile, both should allow the dialogue to be responsive.

😯 Current Behavior

The above code sample shows that the buttons within the dialogue are unresponsive, if called via the OnCompleted task.

💁 Possible Solution

Could the OnCompleted task be detached from the page dispatcher, requiring an InvokeAsync wrapper to reattach it?

🔦 Context

One of our services is Partially Automated Workflows, where the user uploads a file, and needs to confirm that they wish to continue if there are any chargable items within the workflow. This issue stops that process from working.

🌍 Your Environment

  • OS & Device: Windows 11 Enterprise
  • Browser: Tested on Firefox, Edge, Opera, Chrome, and Maxathon
  • Framework Version: net8.0
  • Blazor App: Global InteractiveServer
  • Fluent UI Blazor library Version: 4.11.4

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 36 (23 by maintainers)

Most upvoted comments

@dvoituron might be able to answer that. It is mostly code coming from him.

I’ve tried replicating this and copied the code from above into the demo projects. And for me this works just fine in both Server and WebAssembly.

I’ve tried it in Chrome, Edge and Firefox. And everytime I was able to click each button in the dialog and the result will be displayed for me. Perhaps this has been fixed already with another PR?

I’ll take a look when I have a time slot.

Is there any change needed to the code a developer uses? If so, yes then we need to make it opt-in. If not, then we can change whatever we want.