diff --git a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
index 7d1669e6e0b7a..be589c077003b 100644
--- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
+++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
@@ -278,6 +278,8 @@ export const useGridVirtualScroller = () => {
const forceUpdateRenderContext = () => {
const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
+ // Reset the frozen context when the render context changes, see the illustration in https://github.com/mui/mui-x/pull/12353
+ frozenContext.current = undefined;
updateRenderContext(nextRenderContext);
};
diff --git a/packages/x-data-grid/src/tests/columns.DataGrid.test.tsx b/packages/x-data-grid/src/tests/columns.DataGrid.test.tsx
index 528bb11fc88b4..652d3e9bf1539 100644
--- a/packages/x-data-grid/src/tests/columns.DataGrid.test.tsx
+++ b/packages/x-data-grid/src/tests/columns.DataGrid.test.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
-import { createRenderer } from '@mui/internal-test-utils';
-import { DataGrid, DataGridProps, GridRowsProp, GridColDef } from '@mui/x-data-grid';
+import { createRenderer, fireEvent, screen } from '@mui/internal-test-utils';
+import { DataGrid, DataGridProps, GridRowsProp, GridColDef, gridClasses } from '@mui/x-data-grid';
import { getCell, getColumnHeaderCell, getColumnHeadersTextContent } from 'test/utils/helperFn';
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
@@ -121,4 +121,44 @@ describe(' - Columns', () => {
// should not override valueFormatter with the default numeric one
expect(getCell(0, 0).textContent).to.equal('formatted: 1');
});
+
+ // https://github.com/mui/mui-x/issues/13719
+ it('should not crash when updating columns immediately after scrolling', function test() {
+ if (isJSDOM) {
+ this.skip(); // Needs layout
+ }
+
+ const data = [
+ { id: 1, value: 'A' },
+ { id: 2, value: 'B' },
+ { id: 3, value: 'C' },
+ { id: 4, value: 'D' },
+ { id: 5, value: 'E' },
+ { id: 6, value: 'E' },
+ { id: 7, value: 'F' },
+ { id: 8, value: 'G' },
+ { id: 9, value: 'H' },
+ ];
+
+ function DynamicVirtualizationRange() {
+ const [cols, setCols] = React.useState([{ field: 'id' }, { field: 'value' }]);
+
+ return (
+
+
+
+
+
+
+ );
+ }
+
+ render();
+
+ const virtualScroller = document.querySelector(`.${gridClasses.virtualScroller}`)!;
+ virtualScroller.scrollTop = 1_000;
+ virtualScroller.dispatchEvent(new Event('scroll'));
+
+ fireEvent.click(screen.getByText('Update columns'));
+ });
});