-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Avoid undefined
value for pagination rowCount
#16488
base: master
Are you sure you want to change the base?
Conversation
Deploy preview: https://deploy-preview-16488--material-ui-x.netlify.app/ |
@@ -41,7 +41,7 @@ export const gridPaginationModelSelector = createSelector( | |||
*/ | |||
export const gridPaginationRowCountSelector = createSelector( | |||
gridPaginationSelector, | |||
(pagination) => pagination.rowCount, | |||
(pagination) => pagination.rowCount ?? 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rowCount
is actually undefined
on first render, and the TablePagination
component complains about it, because such a value is not allowed.
WDYT about fallbacking to 0
in such cases?
Or do you have a better suggestion/location of where to solve it? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can the default initial value be 0
instead of the selector fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be the same.
If you know the most proper location to move the initial value fallback to, feel free to make the change. 🙏
undefined
value for pagination rowCount
It's a problem on the v7.x branch as well. |
Is this still happening after #15648? I remember fixing it somehwere – the pagination rowCount wasn't properly initialised, but set in a |
Sadly, yes, big time. 🙈 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to reproduce failing tests locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was "failing" (throwing the warning) 100% of runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Karma or JSDOM? I only tried Karma, but the test was passing.
I'll try again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both are showing the same error.
Did you remember to run pnpm use-react-version ^18.3.1
?
packages/x-data-grid-pro/src/tests/dataSourceTreeData.DataGridPro.test.tsx
Outdated
Show resolved
Hide resolved
@@ -41,7 +41,7 @@ export const gridPaginationModelSelector = createSelector( | |||
*/ | |||
export const gridPaginationRowCountSelector = createSelector( | |||
gridPaginationSelector, | |||
(pagination) => pagination.rowCount, | |||
(pagination) => pagination.rowCount ?? 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can the default initial value be 0
instead of the selector fallback?
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this regression was introduced in https://github.com/mui/mui-x/pull/15666/files#diff-a9fa7340e9088ad1aa390713a020c70597fb321d61f271309c56854d6ea53381
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pagination state initializer depends on rows state, so rows state should be initialized before the pagination state:
mui-x/packages/x-data-grid/src/hooks/features/pagination/useGridPagination.ts
Lines 35 to 36 in 80a0f09
props.initialState?.pagination?.rowCount ?? | |
(props.paginationMode === 'client' ? state.rows?.totalRowCount : undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I broke 40 tests 😅
Something super weird is going on there, I'll dig deeper ⛏️
There's only one test left that is failing with React 18: https://app.circleci.com/pipelines/github/mui/mui-x/81194/workflows/5a59782e-9bb5-45d7-bd79-0942b87c4308/jobs/462244?invite=true#step-107-6123_136 I think this PR is ready to be reviewed and merged, and the remaining failing test can be fixed in a follow-up. |
Yet another similar fix, a follow-up to #16486.
Avoid another warning in tests on React 18.
Avoid these failures:
After fixing the above tests, new ones pop up...
I think we need to fix the root problem. 🙈
@cherniavskii UPDATE: I think I found the root problem. Due to a more effective first mount in SPA mode (i.e. no SSR), some event handlers were not added to the elements because there were no rerenders after the grid was mounted. This PR fixes these issues.
Fixes #16521