Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Submit action on form inside FluentWizardStep with DeferredLoading fire multiple times #3014

Closed
Hwiet opened this issue Dec 4, 2024 · 3 comments
Labels
triage New issue. Needs to be looked at

Comments

@Hwiet
Copy link

Hwiet commented Dec 4, 2024

🐛 Bug Report

When a FluentWizardStep with DeferredLoading contains a form with an submit callback (doesn't matter if it is passed to OnSubmit, OnValidSubmit, OnInvalidSubmit), the callback is fired multiple times, equal to the number of times the step was visited.

💻 Repro or Code Sample

GitHub repository here or recreate something that looks like this that makes it easy to see if a submit action is firing multiple times in a row. Then visit the DeferredLoading step multiple times.

<FluentWizard>
    <Steps>
        <FluentWizardStep Label="Intro">Intro</FluentWizardStep>

        <FluentWizardStep Label="Get started" DeferredLoading>
            <FluentEditForm Model="GetStartedModel" OnSubmit="@(() => ShowSubmitMessageAsync("GetStarted"))">
                GetStarted
            </FluentEditForm>
        </FluentWizardStep>

        <FluentWizardStep Label="Set budget">Set Budget</FluentWizardStep>
    </Steps>
</FluentWizard>

🤔 Expected Behavior

If a wizard step contains a form that has a submit callback, the callback should only be called once when going to the next step, whether or not the step has DeferredLoading or not.

😯 Current Behavior

When I revisit a step with DeferredLoading with a submit callback, the callback is called twice (or more if you keep revisiting the step)

🌍 Your Environment

  • OS & Device: Windows on PC
  • Browser: Microsoft Edge
  • .NET 9 and Fluent UI Blazor 4.10.4
@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Dec 4, 2024
@TumypB
Copy link

TumypB commented Dec 5, 2024

I have the same issue with Google Chrome.

@MarvinKlein1508
Copy link
Contributor

MarvinKlein1508 commented Dec 18, 2024

I can confirm this issue as well. I did some investigation on this and the main cause for this issue seems to be that the EditForm will always be registered to the FluentWizardStep whenever the component will be rendered again. Since DeferredLoading will result in a new reference to a new EditForm everytime.

See:

if (WizardStep is not null && EditContext is not null)

So everytime the component will be rendered again another EditForm will be added to the internal list. Each EditForm will then be invoked here:

foreach (var editForm in _editForms)

To fix this we can clear all EditForm objects from the list in OnStepChangeHandlerAsync. For example:

protected virtual async Task<FluentWizardStepChangeEventArgs> OnStepChangeHandlerAsync(FluentWizardStepChangeEventArgs args)
{
    if (_steps[Value].OnChange.HasDelegate)
    {
        await _steps[Value].OnChange.InvokeAsync(args);
    }

    if (_steps[Value].DeferredLoading && !args.IsCancelled)
    {
        _steps[Value].ClearEditFormAndContext();
    }

    return args;
}

this also requires a way to clear the list from the FluentWizardStep. I've tested it with a basic function like this:

public void ClearEditFormAndContext()
{
    _editForms.Clear();
}

@dvoituron, @vnbaaij let me know what you think and will proceed to create a PR for this.

@vnbaaij
Copy link
Collaborator

vnbaaij commented Dec 18, 2024

@MarvinKlein1508 yes, that seems like a good solution. Please create/submit a PR for it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issue. Needs to be looked at
Projects
None yet
Development

No branches or pull requests

4 participants