Repository navigation
[data grid] Stop the data source polling after the grid unmounts - #23709
Conversation
A request that settles after the grid unmounts calls `startPolling()`. No cleanup clears the new interval, so the unmounted grid keeps calling `getRows()`. `startPolling()` now does nothing after the unmount. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The two lazy-loader guards lack direct regression coverage for requests settling after unmount.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Prevents data-source polling from restarting after grid unmount.
Changes:
- Adds unmount-aware polling guards across data-source implementations.
- Adds a regression test and removes test workarounds.
| File | Description |
|---|---|
packages/x-data-grid/src/tests/dataSource.DataGrid.test.tsx |
Tests polling after unmount. |
packages/x-data-grid/src/hooks/features/dataSource/useGridDataSourceBase.ts |
Guards standard polling. |
packages/x-data-grid-pro/src/tests/dataSourceTreeData.DataGridPro.test.tsx |
Removes polling workarounds. |
packages/x-data-grid-pro/src/hooks/features/serverSideLazyLoader/useGridDataSourceNestedLazyLoader.ts |
Guards nested lazy polling. |
packages/x-data-grid-pro/src/hooks/features/serverSideLazyLoader/useGridDataSourceLazyLoader.ts |
Guards flat lazy polling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A revalidation that `debouncedFetchRows` queued still sent `getRows()` after the grid unmounted. Clear it on a real unmount. A hidden `<Activity>` keeps the root connected, so its queued fetch still runs. The tests now restore real timers in the test body, because `onTestFinished` runs after the global `afterEach`. A new test covers the queued fetch while an `<Activity>` is hidden. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
michelengelen
left a comment
There was a problem hiding this comment.
LGTM... the only suggestion from my side would be to extract the repetitive useEffect into a custom hook that can be imported
I'll look at addressing this separately. |

With
dataSourceRevalidateMsset, each response callsstartPolling(). A request that settles after the grid unmounts restarts the polling. No cleanup clears the new interval, so the unmounted grid keeps callinggetRows()until the page reloads.Changes in
useGridDataSourceBase,useGridDataSourceLazyLoaderanduseGridDataSourceNestedLazyLoader:startPolling()does nothing after the unmount and while an<Activity>is hidden.<Activity>becomes visible again. Before, it did not resume.<Activity>keeps the root connected, so its queued fetch still runs.setProps({ dataSourceRevalidateMs: 0 })workaround from [test] Fix flaky Data Grid Pro data source tree data tests #22659. It worked around the same leak in the tree data tests only.This leak also causes CI flakes. The browser tests run with
isolate: false, so a leaked 1ms poller stays alive in the later test files of the same page. There, eachvi.runAllTimersAsync()spins until it throwsAborting after running 10000 timers, assuming an infinite loop!. In the last 14 days:test_browserandtest_browser_react_18jobs failed insorting.DataGridPro(for example this job on master).columnHeaders.DataGridPro.test.tsx(about 20runAllTimersAsync()calls) never finished (for example this job on master).The tests cover the unmount case for all three hooks, the Activity pause and resume, and the queued fetch while an
<Activity>is hidden. Each test fails when its part of the fix is removed. With allx-data-grid-protest files in one page, no interval stays alive after any file.Generated with Claude Code