-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Initialize apiRef
early
#11792
[DataGrid] Initialize apiRef
early
#11792
Conversation
React tells us not to do that due to concurrent rendering 😬 https://react.dev/learn/referencing-values-with-refs With that being said, we are doing it in |
Deploy preview: https://deploy-preview-11792--material-ui-x.netlify.app/ |
I don't see concurrent rendering mentioned on that page.
And I think this PR falls under the exception mentioned above - it's only assigned once because of the |
@@ -311,6 +312,7 @@ describe('<DataGrid /> - Rows', () => { | |||
await waitFor(() => { | |||
expect(getRow(0)).not.to.have.class('Mui-selected'); | |||
}); | |||
await microtasks(); |
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.
It's not related to this PR, it's just a fix for the flaky test that fails from time to time: https://app.circleci.com/pipelines/github/mui/mui-x/49318/workflows/26e5b314-bb45-4771-8095-330e1f96670b/jobs/282851
It failed again in this PR, this is why I added a fix here.
From what I understand, the reason behind the fact that we should not mutate the ref in the render is the concurrent mode, at least that's what this Stackoverflow answers thinks.
Once again, in the doc there is no explicit mention of why you should not do it, just some blurry words like "behavior unpredictable". |
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.
LGTM. I don't think those notes in the react docs are applicable to us.
Open a new issue with details, make sure to search past issues for a duplicate. |
I need this for #11164, where I use
apiRef
in thesortComparator
for the grouping column +sortingModel
in theinitialState
.The demo throws an error, because when initial sorting happens the
apiRef
is not initialized yet (this is also the reason why Netlify deployment fails)A simpler example to illustrate the issue:
Before: https://codesandbox.io/p/sandbox/gallant-wu-gh2svt
After: https://codesandbox.io/p/sandbox/heuristic-spence-nmkx2w