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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cyclical, uncontrolled input value changes when using Fast input components in Blazor Server #304

Closed
MackinnonBuck opened this issue Jan 27, 2023 · 0 comments 路 Fixed by #306

Comments

@MackinnonBuck
Copy link
Member

馃悰 Bug Report

When using Blazor server (particularly when there is high latency between the server and the browser), Fast input controls may rapidly cycle between values previously provided by the user.

The most straightforward example of this is when using the <FluentRadioGroup> and <FluentRadio> components, but #152 seems to indicate that other Fast input components are impacted by this bug as well.

If the user clicks two radio buttons before the server is able to handle the first click and re-render the parent component, then the component gets stuck in a loop, cycling between having the first and second radio options selected. If you then click a third radio button as this is happening, that button gets added to the cycle.

I haven't been able to get to the bottom of why this is happening, but I have a theory:

  1. The user clicks the first radio button, and the selection is sent to the server.
  2. The server re-renders the form (e.g., because a ValueChanged callback was registered) and sends off a new render batch to the browser.
  3. While the new render batch is in transit, the user clicks the second radio button. The new selection is sent to the server.
  4. The render batch from the first re-render gets received, changing the selected radio button back to the first one. Since the radio group's value has just changed, the new selection is sent to the server.
  5. The render batch from the second re-render gets received, changing the selected radio button back to the second one. Since the radio group's value has just changed, the new selection is sent to the server.
  6. The state of the world is exactly the same as it was in step 4, so an infinite loop is created.

It should be noted that the <InputRadio> component from Microsoft.AspNetCore.Components.Forms does NOT exhibit this behavior.

Screen recording:

fast_blazor_inf_loop.mp4

馃捇 Repro or Code Sample

  1. Create a new Blazor Server project.
  2. Add a package reference to Microsoft.Fast.Components.FluentUI, version 2.0.2.
  3. Replace the code in Index.razor with the following:
@page "/"

<FluentRadioGroup ValueChanged="@(() => { /* No-op */ })">
    <FluentRadio Value="1">1</FluentRadio>
    <FluentRadio Value="2">2</FluentRadio>
    <FluentRadio Value="3">3</FluentRadio>
</FluentRadioGroup>

@code {
    protected override bool ShouldRender()
    {
        // Simulate a laggy render (or a late response).
        Thread.Sleep(500);
        return true;
    }
}
  1. Run the project. Click the first two radio buttons in quick succession to make the bug occur.

馃 Expected Behavior

When the UI finishes rendering, the second radio button is selected.

馃槸 Current Behavior

The UI continuously re-renders, alternating between having the first and second radio buttons selected.

馃拋 Possible Solution

Don't notify .NET about changes to radio button selection unless they were initiated by a click (or touch) event.

馃實 Your Environment

  • OS & Device: Windows 11
  • Browser: Microsoft Edge, Google Chrome
  • .NET version: 6.0
  • FAST version: Tried 1.1.0 and 2.0.2, the bug reproduced on both.
vnbaaij added a commit that referenced this issue Jan 30, 2023
FluentInputBase: _hasInitialized... requires @bind-Value

Reboot.css: Inherit font-family for headers
vnbaaij added a commit that referenced this issue Jan 31, 2023
vnbaaij added a commit that referenced this issue Jan 31, 2023
vnbaaij added a commit that referenced this issue Jan 31, 2023
Make more custom event work (Accordion, tooltip, menu, dialog)
Ignore publish dir
vnbaaij added a commit that referenced this issue Jan 31, 2023
Make more custom event work (Accordion, tooltip, menu, dialog)
Ignore publish dir
@vnbaaij vnbaaij mentioned this issue Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant