Skip to content

[DataGridPro] Fix lazy loading params for page with one row#21139

Merged
MBilalShafi merged 9 commits intomui:masterfrom
MBilalShafi:lazy-loading-params-fix
Feb 6, 2026
Merged

[DataGridPro] Fix lazy loading params for page with one row#21139
MBilalShafi merged 9 commits intomui:masterfrom
MBilalShafi:lazy-loading-params-fix

Conversation

@MBilalShafi
Copy link
Copy Markdown
Member

@MBilalShafi MBilalShafi commented Jan 28, 2026

Summary

The lazy loader hook was miscalculating pagination parameters for single-row pages, causing them to remain unfetched. This PR extracts the core utility function to enable proper testing and reusability in follow-up improvements.

Problem

When a page contained only a single row, the lazy loading params calculation would incorrectly cap the row count at -1, preventing the data from being fetched and leaving the loader in an infinite loading state.

Solution

Key Changes:

  • Extracted adjustRowParams as a pure utility function for better testability
  • Fixed the params calculation logic to handle single-row pages correctly

Impact

  • ✅ Single-row pages now load correctly without infinite loading states
  • 🧪 Utility function is now independently testable and reusable
  • 🔧 Foundation for related improvements in [DataGridPremium] Nested Lazy Loading #21043

Testing

  • Unit tests for adjustRowParams utility function
  • Verified single-row page loading scenarios

Fixes #21104

@MBilalShafi MBilalShafi added type: bug It doesn't behave as expected. scope: data grid Changes related to the data grid. plan: Pro Impact at least one Pro user. feature: Server integration Better integration with backends, e.g. data source labels Jan 28, 2026
@mui-bot
Copy link
Copy Markdown

mui-bot commented Jan 28, 2026

Deploy preview: https://deploy-preview-21139--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 🔺+173B(+0.03%) 🔺+73B(+0.05%)
@mui/x-data-grid-premium 🔺+173B(+0.03%) 🔺+67B(+0.03%)
@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%)

Details of bundle changes

Generated by 🚫 dangerJS against 010d666

MBilalShafi and others added 4 commits January 30, 2026 00:53
- Move adjustRowParams from useGridDataSourceLazyLoader hook to lazyLoader/utils.ts
- Make it a pure function with explicit pageSize and rowCount parameters
- Fix edge case where rowCount of 0 would result in negative end index
- Add unit tests for the utility function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use a more specific GridRowRenderContext type that only requires
firstRowIndex and lastRowIndex, instead of the full GridRenderContext
which also requires column indices that aren't used by the function.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove export from GridRowRenderContext and AdjustRowParamsOptions
interfaces as they are only used internally.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When rowCount is -1 (infinite/unknown), the adjustRowParams function
was incorrectly calculating maxEnd as Math.max(0, -2) = 0, which
capped all requests at end=0. This fix treats rowCount=-1 the same
as undefined, allowing infinite loading to fetch rows without capping.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test case for issue mui#21104 where rowCount % pageSize === 1
(e.g., rowCount=31 with pageSize=10) to verify the last page
with a single row is correctly fetched.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@MBilalShafi MBilalShafi requested a review from arminmeh January 30, 2026 12:01
@maxhollmann
Copy link
Copy Markdown

Do you have a rough estimate when this will be merged & released? I need to decide whether to hack around this bug or if we can wait for the fix and tolerate it that long...

@arminmeh
Copy link
Copy Markdown
Contributor

arminmeh commented Feb 5, 2026

Do you have a rough estimate when this will be merged & released? I need to decide whether to hack around this bug or if we can wait for the fix and tolerate it that long...

@maxhollmann, I will finish my review soon, and it should be merged soon and released next week.

@arminmeh arminmeh added needs cherry-pick The PR should be cherry-picked to master after merge. v8.x labels Feb 5, 2026
@MBilalShafi MBilalShafi merged commit 23e801a into mui:master Feb 6, 2026
28 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 6, 2026

Cherry-pick PRs will be created targeting branches: v8.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: Server integration Better integration with backends, e.g. data source needs cherry-pick The PR should be cherry-picked to master after merge. plan: Pro Impact at least one Pro user. scope: data grid Changes related to the data grid. type: bug It doesn't behave as expected. v8.x

Projects

None yet

4 participants