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] Only update input with value prop if debounce is off #5646

Merged
merged 5 commits into from
Sep 14, 2022

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Jul 28, 2022

Fixes #5283

Preview: https://deploy-preview-5646--material-ui-x.netlify.app/x/react-data-grid/editing/

I don't have a precise explanation of why #5283 happens but I have a hypothesis. On each keystroke we call apiRef.current.setEditCellValue which debounces the state updates. When the debounce time expires, the global state is updated triggering a rerender of the entire grid. While the grid is rerendering, sometimes taking a long time, if the user presses another key this last key will be lost because the input value is changed to reflect the value in the state. I solved this problem here by ignoring the sync between the value in the global state and the value in the edit component's state when the reason for this sync to happen is a debounce event. In practical terms, apiRef.current.setEditCellValue now has a reason argument which can be accessed via apiRef.current.unstable_getEditCellMeta.

@m4theushw m4theushw added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Jul 28, 2022
@mui-bot
Copy link

mui-bot commented Jul 28, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 494.9 846.9 558.7 658.64 152.248
Sort 100k rows ms 556.6 1,078.5 798.4 843.1 171.342
Select 100k rows ms 150.8 358 220.7 245.14 72.856
Deselect 100k rows ms 127.1 270.5 215.2 208.9 46.159

Generated by 🚫 dangerJS against 78ca78f

@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 Jul 29, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 5, 2022
@m4theushw m4theushw marked this pull request as ready for review September 5, 2022 23:36

let parsedValue = newValue;
if (column.valueParser && rootProps.experimentalFeatures?.newEditingApi) {
parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we don't sync the value between the global state and the local state, when the call is debounced, we need to manually call the value parser and skip the one in apiRef.current.setEditCellValue.

@DanailH DanailH changed the base branch from master to next September 12, 2022 13:05
@m4theushw m4theushw changed the base branch from next to master September 12, 2022 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work 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.

[data grid] Lag while typing
3 participants