Skip to content

[test] Fix flaky "should render only the pageSize" Data Grid virtualization test#23090

Merged
LukasTy merged 1 commit into
mui:masterfrom
LukasTy:fix-flaky-pagesize-virtualization-test
Jul 6, 2026
Merged

[test] Fix flaky "should render only the pageSize" Data Grid virtualization test#23090
LukasTy merged 1 commit into
mui:masterfrom
LukasTy:fix-flaky-pagesize-virtualization-test

Conversation

@LukasTy

@LukasTy LukasTy commented Jul 6, 2026

Copy link
Copy Markdown
Member

Problem

The browser test <DataGridPro /> - Rows > virtualization > Pagination > should render only the pageSize fails intermittently in CI (for example CircleCI build https://circleci.com/gh/mui/mui-x/877236, which surfaced on the unrelated Renovate PR #23083 that only bumps @tanstack/query in the docs):

AssertionError: expected div.MuiDataGrid-cell...[title="7"] to have text '31', but the text was '7'

Cause

The test scrolls the virtual scroller to the bottom and then asserts the last rendered cell synchronously, with no waitFor:

await act(async () => virtualScroller.scrollTo({ top: 2000 }));
const lastCell = ...;
expect(lastCell).to.have.text('31');

scrollTo updates scrollTop synchronously, but the browser dispatches the native scroll event asynchronously. The grid updates its render context only from that event (handleScroll -> triggerUpdateRenderContext -> ReactDOM.flushSync). When the assertion runs before the scroll event fires, the DOM still shows the initial top window, so the last cell reads its initial value (7) instead of the expected 31. Under CI load the event is sometimes late, hence the flake.

The sibling test should not virtualize the last page if smaller than viewport is not affected: its last page fits within the viewport, so the scroll is clamped to 0 and no re-render is needed.

Fix

Wrap the assertion in waitFor, matching the convention already used by every other scroll test in this file.

Test plan

Ran the browser test suite for the file locally; the target test and the full rows.DataGridPro.test.tsx (47 tests) pass.

🤖 Generated with Claude Code

… test

The test scrolled the virtual scroller to the bottom and then asserted the
last rendered cell synchronously, with no waitFor. `scrollTo` updates
`scrollTop` synchronously, but the browser dispatches the native `scroll`
event asynchronously, and the grid's render context is updated only from
that event (handleScroll -> triggerUpdateRenderContext -> flushSync). When
the assertion runs before the scroll event fires, the DOM still shows the
initial top window, so the last cell reads its initial value instead of the
expected one, failing intermittently in CI.

Wrap the assertion in waitFor, matching the convention already used by the
sibling scroll tests in this file.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@LukasTy LukasTy added test scope: data grid Changes related to the data grid. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Jul 6, 2026
@LukasTy LukasTy self-assigned this Jul 6, 2026
@LukasTy LukasTy changed the title [DataGrid] Fix flaky "should render only the pageSize" virtualization test [test] Fix flaky "should render only the pageSize" Data Grid virtualization test Jul 6, 2026
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23090--material-ui-x.netlify.app/
QR code for https://deploy-preview-23090--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

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.

Pull request overview

This PR fixes an intermittent browser-test failure in the Data Grid Pro rows virtualization pagination suite by waiting for the render context to update after a programmatic scrollTo, eliminating a race between synchronous scrollTop changes and asynchronous native scroll event dispatch.

Changes:

  • Wrap the “last rendered cell” assertion in waitFor so it retries until the bottom window is actually rendered.
  • Add an inline comment explaining why the wait is necessary (async scroll event + render context update path).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LukasTy
LukasTy merged commit 70197fa into mui:master Jul 6, 2026
26 of 27 checks passed
@LukasTy
LukasTy deleted the fix-flaky-pagesize-virtualization-test branch July 6, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: data grid Changes related to the data grid. test type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants