Skip to content

[dev-v5] fix: @bind-xxx:after is being executed twice in FluentAutocomplete #4754

@MarvinKlein1508

Description

@MarvinKlein1508

🐛 Bug Report

The @bind-SelectedItems:after and @bind-SelectedItem:after callbacks are executed twice in FluentAutocomplete when you select an item.

💻 Repro or Code Sample

<div>
    Current count: <span data-testid="current-value">@countAfter</span>
</div>

<FluentAutocomplete TValue="string"
                    TOption="string"
                    Label="Test"
                    Items="Options"
                    @bind-SelectedItems="SelectedItems"
                    @bind-SelectedItems:after="AfterChanged" />

@code
{
    string test = string.Empty;
    int countAfter = 0;
    IEnumerable<string> SelectedItems { get; set; } = [];

    void AfterChanged()
    {
        countAfter++;
    }

    List<string> Options = new List<string>
    {
        "Option 1",
        "Option 2",
        "Option 3",
        "Option 4",
        "Option 5"
    };
}
  1. Run the code
  2. Click on the component
  3. Select an item
  4. See count is 2 instead of 1

🤔 Expected Behavior

I expect the method to be executed once.

😯 Current Behavior

I expect the method will be executed twice.

💁 Possible Solution

🔦 Context

I created this PR with an integration test for this case #4753

For some reason if you try to validate it in the normal unit tests the count will always be 1.

🌍 Your Environment

  • OS & Device: Windows 11 64 Bit
  • Browser latest Firefox Chrome & Edge
  • latest dev-v5 branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bugv5For the next major version

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions