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] Prevent commit if preProcessEditCellProps resolves with an error #3612

Merged
merged 10 commits into from Jan 27, 2022

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Jan 13, 2022

Fixes #3304

Before: https://codesandbox.io/s/datagridpro-v5-quick-start-forked-pxc4e?file=/src/App.tsx

After: https://codesandbox.io/s/datagridpro-v5-quick-start-forked-rzyrl?file=/src/App.tsx

The bug happens because we don't keep a track if the validation is running or not. With singleSelect, the preProcessEditCellProps is called when the value is changed and also when commiting, which occur at the same time in this component. To fix it, we should have a flag tracking when the validation is running or not. If it's running, we don't commit the value nor call the callback again. To properly implement this, it involves changing the state which, since the state is passed to all edit components as props, could cause a warning if users spread the props directly into the DOM node without sanitizing them. Since we can't release that breaking change, I added temporarily a new prop called preventCommitWhileValidating for users to opt-in. Once it's enabled, we update the isValidating prop in the editing state before and after calling preProcessEditCellProps. During commit we check if it's validating or not. In v6 I want to make that the default behavior and remove the temp prop.

The code is very ugly. There're opportunities to refactor it but it's better to do it after #3219.

If you open the CodeSandbox above, you may notice that it only updates the Select value after preProcessEditCellProps has resolved. That's another PR.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 18, 2022
@github-actions
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 Jan 18, 2022
@mui-bot
Copy link

mui-bot commented Jan 18, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 146.4 385.9 250 251.72 87.278
Sort 100k rows ms 317.5 652.1 605.4 527.18 127.256
Select 100k rows ms 148.7 328.8 189.2 207.02 64.055
Deselect 100k rows ms 123.9 217 168.8 166.12 34.213

Generated by 🚫 dangerJS against 369d4f9

Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

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

If preventCommitWhileValidating is temporary, maybe we could put it under experimentalFeatures ?
Or at least explain on the doc that we only add this strange prop temporarily to avoid any breaking change and that it will be removed on v6.

@github-actions
Copy link

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

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 19, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 26, 2022
@m4theushw
Copy link
Member Author

If preventCommitWhileValidating is temporary, maybe we could put it under experimentalFeatures ?

@flaviendelangle I moved to experimentalFeatures. I had to make other changes to have access to this prop inside the hook. For the row grouping, you created an additional prop besides the one in experimentalFeatures.

Copy link
Member

@flaviendelangle flaviendelangle left a comment

Choose a reason for hiding this comment

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

@m4theushw yes for the row grouping, disableRowGrouping made sense even when the feature will be marked as stable.

@m4theushw m4theushw merged commit 972f775 into mui:master Jan 27, 2022
@m4theushw m4theushw deleted the validation-with-promise branch January 27, 2022 17:04
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Jan 17, 2023
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] - singleSelect is calling the preProcessEditCellProps twice. The second call has wrong value.
4 participants