Skip to content
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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

LukasTy
Copy link
Member

@LukasTy LukasTy commented Feb 6, 2025

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

@LukasTy LukasTy added the test label Feb 6, 2025
@LukasTy LukasTy self-assigned this Feb 6, 2025
@mui-bot
Copy link

mui-bot commented Feb 6, 2025

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

Generated by 🚫 dangerJS against ff9bbef

@@ -41,7 +41,7 @@ export const gridPaginationModelSelector = createSelector(
*/
export const gridPaginationRowCountSelector = createSelector(
gridPaginationSelector,
(pagination) => pagination.rowCount,
(pagination) => pagination.rowCount ?? 0,
Copy link
Member Author

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? 🤔

Copy link
Contributor

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?

Copy link
Member Author

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. 🙏

@LukasTy LukasTy changed the title [test] Avoid another warning in tests on React 18 [DataGrid] Avoid undefined value for pagination rowCount Feb 7, 2025
@LukasTy LukasTy added the component: data grid This is the name of the generic UI component, not the React module! label Feb 7, 2025
@LukasTy LukasTy requested a review from a team February 7, 2025 11:48
@LukasTy LukasTy added needs cherry-pick The PR should be cherry-picked to master after merge v7.x labels Feb 7, 2025
@lauri865
Copy link
Contributor

lauri865 commented Feb 7, 2025

Is this still happening after #15648? I remember fixing it somehwere – the pagination rowCount wasn't properly initialised, but set in a useEffect.

@LukasTy
Copy link
Member Author

LukasTy commented Feb 7, 2025

Is this still happening after #15648? I remember fixing it somehwere – the pagination rowCount wasn't properly initialised, but set in a useEffect.

Sadly, yes, big time. 🙈
Every single pipeline is 🔴: https://app.circleci.com/pipelines/github/mui/mui-x?branch=master

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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?

@@ -41,7 +41,7 @@ export const gridPaginationModelSelector = createSelector(
*/
export const gridPaginationRowCountSelector = createSelector(
gridPaginationSelector,
(pagination) => pagination.rowCount,
(pagination) => pagination.rowCount ?? 0,
Copy link
Contributor

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?

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 10, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 11, 2025
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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:

props.initialState?.pagination?.rowCount ??
(props.paginationMode === 'client' ? state.rows?.totalRowCount : undefined);

Copy link
Member

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 ⛏️

@cherniavskii cherniavskii added the regression A bug, but worse label Feb 11, 2025
@cherniavskii
Copy link
Member

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 believe it's related to #16394 (comment)

I think this PR is ready to be reviewed and merged, and the remaining failing test can be fixed in a follow-up.

@cherniavskii cherniavskii requested a review from a team February 12, 2025 12:32
@cherniavskii cherniavskii assigned cherniavskii and unassigned LukasTy Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! needs cherry-pick The PR should be cherry-picked to master after merge regression A bug, but worse test v7.x
Projects
None yet
5 participants