Skip to content

fix: multiple (inifinite) remote calls in fluentdatagrid 5.x.x #5487

Closed

Description

@damiand2

🐛 Bug Report

in Fluentui v5 following official example (https://www.fluentui-blazor.net/DataGrid/RemoteData#remote-data-with-refreshitems) results in multiple (or even infinite loop) calls to backend api when pressing search button (invoking dataGrid.RefreshDataAsync(true))

💻 Repro or Code Sample

create new blazor app and paste into any page code from documentation url from above

🤔 Expected Behavior

there should be single call to backend api after invoking refreshdataasync call. Removing code
loading = true;
await InvokeAsync(StateHasChanged); with matching code at the end (loading false, etc.)
seems to remedy this issue, however without it grid does not give feedback that something is happening

😯 Current Behavior

With example code as-is (with setting loading variable and invoking statehaschanged) results in 7 calls to backend on sample code and infinite calls to backen on my real project (which is also surprising)

💁 Possible Solution

i could not find acceptable workaround so far

🔦 Context

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]

Activity

  1. added a commit that references this issue on Oct 21, 2026
    b9e3bd8
  2. Neil-WeiLinYao commented on Nov 2, 2026

    @Neil-WeiLinYao

    Hi FluentUI teams, I found the issue still exist in V5.0.1, and I notice that you had fixed that bug and merged the code, so it will be effect in V5.0.2? when would you release the next version, I need to upgrade it as soon as possible.

  3. vnbaaij commented on Nov 2, 2026

    @vnbaaij
    Collaborator

    It will still be a couple of weeks before v5.1 (instead of 5.0.2) will be released

  4. Neil-WeiLinYao commented on Nov 2, 2026

    @Neil-WeiLinYao

    5. It will still be a couple of weeks before v5.1 (instead of 5.0.2) will be released

    Hi Vincent, do you have a workaround so far? I tried to add a flag "LoadingFinished " to fix that issue, seems it's ok when click the search button. but it brings another issue, that is the Paginator component doesn't work when I turn to next page.

    the following codes is a part of my logic, I'm not sure where is the problem!

    protected bool LoadingFinished = false;
    private readonly SemaphoreSlim _asyncLock = new(1, 1); 
      
    protected virtual async Task DataGridRefreshDataAsync()
    {
      if (grid != null) 
      {
    	  LoadingFinished = false;
    	  await grid.RefreshDataAsync(true);
      }
    }
    
    protected virtual async Task RefreshItemsAsync(GridItemsProviderRequest<TModel> req)
    {
         
        await _asyncLock.WaitAsync();
        try
        {
            if (LoadingFinished)
                return;
    
            loading = true;
            await InvokeAsync(StateHasChanged);
    
            // call remote api ...
    
            loading = false;
            LoadingFinished = true;
        }
        catch (Exception)
        {
            loading = false;
        }
        finally 
        {
            _asyncLock.Release();
        }
        await InvokeAsync(StateHasChanged);
    }
    
  5. vnbaaij commented on Nov 2, 2026

    @vnbaaij
    Collaborator

    I'm not at a PC for a while so can't help with that.

    You can try the preview version of the package to see if that solves your problem. See https://github.com/microsoft/fluentui-blazor/blob/dev/docs%2Fusing-latest-daily.md

  6. Neil-WeiLinYao commented on Nov 2, 2026

    @Neil-WeiLinYao

    thank you guys! I have found a way to avoid this issue, I adjust the codes as bellow, it works well now,hope it's helpfull for you!

    protected virtual async Task RefreshItemsAsync(GridItemsProviderRequest<TModel> req)
    {
    
        SortField? sortField = null;
        var s = req.GetSortByProperties().FirstOrDefault();
        if (req.SortColumns != null && !string.IsNullOrEmpty(s.PropertyName))
        {
            sortField = new SortField()
            {
                FieldName = s.PropertyName,
                Direction = s.Direction == DataGridSortDirection.Descending ? SortDirection.DESC : SortDirection.ASC
            };
        }
        await FetchRemoteDataAsync(sortField);
    
    }
    
    protected virtual async Task FetchRemoteDataAsync(SortField? sortField)
    {
        loading = true;
        await InvokeAsync(StateHasChanged);
        var page = new PageDto()
        {
            PageIndex = pagination.CurrentPageIndex,
            PageSize = pagination.ItemsPerPage,
            SortField = sortField
        };
        try
        {
            var dataList = await LoadRemoteDataAsync(searchCondition, page);
            if (dataList.Result != null)
            {
                var dateFiltered = FilterRemoteData(dataList.Result);
                dataInfoList = dateFiltered.AsQueryable();
                await pagination.SetTotalItemCountAsync(dataList.TotalCount);
            }
        }
        finally 
        {
            loading = false;
        }
        await InvokeAsync(StateHasChanged);
    
    }
    
       protected virtual async Task DataGridRefreshDataAsync()
        {
            if (grid != null) 
            {
                await pagination.SetCurrentPageIndexAsync(0);
                await FetchRemoteDataAsync(defaultSortField);
            }
               
        }
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions