diff --git a/packages/x-data-grid-pro/src/tests/rowEditing.DataGridPro.test.tsx b/packages/x-data-grid-pro/src/tests/rowEditing.DataGridPro.test.tsx
index fa67b53ae0f15..b510d3bc63fdb 100644
--- a/packages/x-data-grid-pro/src/tests/rowEditing.DataGridPro.test.tsx
+++ b/packages/x-data-grid-pro/src/tests/rowEditing.DataGridPro.test.tsx
@@ -1260,6 +1260,15 @@ describe(' - Row editing', () => {
expect(getCell(0, 1)).not.to.have.class('MuiDataGrid-cell--editing');
});
+ it('should stop edit mode when rowModesModel empty', () => {
+ const { setProps } = render(
+ ,
+ );
+ expect(getCell(0, 1)).to.have.class('MuiDataGrid-cell--editing');
+ setProps({ rowModesModel: {} });
+ expect(getCell(0, 1)).not.to.have.class('MuiDataGrid-cell--editing');
+ });
+
it('should ignode modifications if ignoreModifications=true', async () => {
const { setProps } = render(
,
diff --git a/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts b/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts
index 95882331db340..33932d80672f3 100644
--- a/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts
+++ b/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts
@@ -718,7 +718,9 @@ export const useGridRowEditing = (
const copyOfPrevRowModesModel = prevRowModesModel.current;
prevRowModesModel.current = deepClone(rowModesModel); // Do a deep-clone because the attributes might be changed later
- Object.entries(rowModesModel).forEach(([id, params]) => {
+ const ids = new Set([...Object.keys(rowModesModel), ...Object.keys(copyOfPrevRowModesModel)]);
+ Array.from(ids).forEach((id) => {
+ const params = rowModesModel[id] ?? { mode: GridRowModes.View };
const prevMode = copyOfPrevRowModesModel[id]?.mode || GridRowModes.View;
const originalId = idToIdLookup[id] ?? id;
if (params.mode === GridRowModes.Edit && prevMode === GridRowModes.View) {