Skip to content

[DataGrid] Clear the force-refresh flag before calling RefreshItems - #5490

Merged
Denis Voituron (dvoituron) merged 2 commits into
microsoft:devfrom
nurullahturkoglu:fix/datagrid-force-refresh-5487
Oct 21, 2026
Merged

Denis Voituron (dvoituron) merged 2 commits into
microsoft:devfrom
nurullahturkoglu:fix/datagrid-force-refresh-5487

Conversation

@nurullahturkoglu

Copy link
Copy Markdown

Pull Request

📖 Description

RefreshDataAsync(force: true) sets _forceRefreshData, but RefreshDataCoreAsync only cleared it after RefreshItems returned. The remote data sample with RefreshItems sets loading = true and calls StateHasChanged inside RefreshItems. That re-renders the grid, and because Loading is true, OnParametersSetAsync calls RefreshDataCoreAsync again while the flag is still set, so RefreshItems runs again. Each call starts the next one, which gives the repeated or endless backend calls described in #5487.

v4 clears the flag before it invokes RefreshItems (since #3423, kept in #3927). The v5 port in #3915 moved the reset after the call. This PR restores the v4 order. It's a bug fix with no breaking change.

🎫 Issues

Fix #5487

👩‍💻 Reviewer Notes

Only the forced path was affected. Without force, _lastRequest is set before the call, and IsSameRequest already stops the re-entrant call.

📑 Test Plan

I added FluentDataGrid_RefreshDataAsync_ForceRefresh_RerenderWhileLoading_CallsRefreshItemsOnce. Its RefreshItems re-renders the grid with Loading = true, like the sample. Without the fix, RefreshItems is called 10 times, which is the limit the test sets, instead of 2. With the fix it is called twice: once for the initial load and once for the forced refresh.

I ran all of tests/Core (net10.0, macOS arm64): 4904 passed, 0 failed. I didn't run the demo app in a browser.

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

AI contribution declaration

AI assistance is allowed; fully AI-generated or autonomous pull requests without meaningful human review are not accepted. See the AI contribution policy.

  • I have read and followed the AI contribution policy.
  • I have personally reviewed and understood all changes, tested them, and take responsibility for this contribution.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

RefreshDataCoreAsync cleared _forceRefreshData only after RefreshItems
returned. When RefreshItems sets Loading and re-renders the grid, as the
remote data sample does, OnParametersSetAsync refreshes again while the
flag is still set and RefreshItems is called again. Clear the flag
before the call, as v4 does.

Fix microsoft#5487

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The targeted fix addresses both callback paths, and the regression test covers the reported failure.

No open issues 🎉

What changed in this PR

Fixes #5487 by preventing repeated remote-data requests during forced DataGrid refreshes.

Changes:

  • Clears the force-refresh flag before invoking RefreshItems in both branches.
  • Adds a regression test for re-rendering while loading.
File Description
tests/​Core/​Components/​DataGrid/​FluentDataGridTests.razor Tests that loading re-renders do not trigger extra refresh callbacks.
src/​Core/​Components/​DataGrid/​FluentDataGrid.razor.cs Resets the force-refresh flag before callback invocation.

Review effort: Balanced

@nurullahturkoglu

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@dvoituron
Denis Voituron (dvoituron) merged commit b9e3bd8 into microsoft:dev Oct 21, 2026
4 checks passed
This was referenced Nov 16, 2026
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 this pull request may close these issues.

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

3 participants