-
-
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
[core] Rework useGridRows high frequency update #2561
Conversation
|
As I built it, the @oliviertassinari , @m4theushw what is your view on that topic ? |
packages/grid/_modules_/grid/hooks/features/rows/gridRowsState.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/rows/useGridRows.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/features/rows/useGridRows.ts
Outdated
Show resolved
Hide resolved
@@ -266,4 +272,5 @@ export const GRID_DEFAULT_SIMPLE_OPTIONS: GridSimpleOptions = { | |||
showColumnRightBorder: false, | |||
sortingOrder: ['asc' as const, 'desc' as const, null], | |||
sortingMode: GridFeatureModeConstant.client, | |||
throttleRowsMs: 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.
Should we keep the 100ms as default? AG-Grid uses 50ms: https://ag-grid.com/javascript-data-grid/data-update-high-frequency/#flush-async-transactions
If we change the default value, we need to update the useEffect
to run immediately when the prop changes. I think throttleRowsMs
is only for setRows
and updateRows
.
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.
My idea was to let the default value at 0
and if the user defines a throttle value, then it applies even on rows update.
But if you prefer to have a default value other than 0
, then we should probably not run throttle the props update.
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.
Let's keep the default as 0
. I remembered that we don't have a separate method for throttled updates, so having a non-zero default will affect updateRows
too.
With this PR, it should be possible to remove the following setTimeout
:
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.
We just need to wait for the next render in order to focus
const handleClick = () => {
const id = randomId();
apiRef.current.updateRows([{ id, isNew: true }]);
apiRef.current.setRowMode(id, 'edit');
setTimeout(() => {
apiRef.current.scrollToIndexes({
rowIndex: apiRef.current.getRowsCount() - 1,
});
apiRef.current.setCellFocus(id, 'name');
})
};
Screencast.2021-09-13.14.49.58.mp4
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.
We could think of a better API to do so later on
I would keep it only for the API calls. Users can throttle the prop update in their applications. Once I have a value for |
@mui-org/x can we merge this PR once the release is done ? |
@@ -218,6 +218,12 @@ export interface GridSimpleOptions { | |||
* @default "client" | |||
*/ | |||
sortingMode: GridFeatureMode; | |||
/** | |||
* If positive, the Grid will throttle updates coming from `apiRef.current.updateRows` and `apiRef.current.setRows`. | |||
* It can be useful if you have a high update rate but do not want to do heavy work like filtering / sorting or rendering on each individual update. |
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.
AFAIK, no spaces when using a slash, unless it's separating multiple words.
* It can be useful if you have a high update rate but do not want to do heavy work like filtering / sorting or rendering on each individual update. | |
* It can be useful if you have a high update rate but do not want to do heavy work like filtering/sorting or rendering on each individual update. |
Preview: https://deploy-preview-2561--material-ui-x.netlify.app/components/data-grid/rows/#high-frequency
throttleRowsMs
optionGridEvents.rowsClear
andGridEvents.rowsUpdate
InternalGridRowsState
=>GridRowsState
for consistencyNew option
props.throttleRowsMs
I think it's better to let the user choose if he wants to throttle or not.
Today, every Grid has a 100ms delay on update even if it's not useful in most cases.
I went for a throttle instead of a debounce to avoid scenarios when we never have enough time between two updates so we never update the state.
Consequences on the events
Before, we were updating the state when receiving an update but we weren't publishing the event right away.
I think we should avoid that.
Now, the state is only updated after the throttle period if any. And the event is published at the same time.
By default (and in the large majority of cases), their is no throttle so the update of the rows is as synchronous as any other update.