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] Fix react 17 editing bug #9530

Merged
merged 8 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function GridEditDateCell(props: GridEditDateCellProps) {
const handleInputRef = (el: HTMLInputElement) => {
inputRef.current = el;

if (meta.unstable_updateValueOnRender && !hasUpdatedEditValueOnMount.current) {
if (meta?.unstable_updateValueOnRender && !hasUpdatedEditValueOnMount.current) {
const inputValue = inputRef.current.value;
const parsedDate = parseValueToDate(inputValue);
setValueState({ parsed: parsedDate, formatted: inputValue });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ const GridEditInputCell = React.forwardRef<HTMLInputElement, GridEditInputCellPr
[apiRef, debounceMs, field, id, onValueChange],
);

const meta = apiRef.current.unstable_getEditCellMeta
? apiRef.current.unstable_getEditCellMeta(id, field)
: {};
const meta = apiRef.current.unstable_getEditCellMeta(id, field);

React.useEffect(() => {
if (meta.changeReason !== 'debouncedSetEditCellValue') {
if (meta?.changeReason !== 'debouncedSetEditCellValue') {
setValueState(value);
}
}, [meta.changeReason, value]);
}, [meta, value]);

useEnhancedEffect(() => {
if (hasFocus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const useGridEditing = (
const getEditCellMeta = React.useCallback<GridEditingSharedApi['unstable_getEditCellMeta']>(
(id, field) => {
const editingState = gridEditRowsStateSelector(apiRef.current.state);
return editingState[id][field];
return editingState[id]?.[field] ?? null;
},
[apiRef],
);
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/x-data-grid/src/models/api/gridEditingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface GridEditingSharedApi {
* @param {string} field The field being edited.
* @ignore - do not document.
*/
unstable_getEditCellMeta: (id: GridRowId, field: string) => GridEditCellMeta;
unstable_getEditCellMeta: (id: GridRowId, field: string) => GridEditCellMeta | null;
}

export interface GridEditingSharedPrivateApi {
Expand Down