From 421fa668027a12cc723425e01669bde693d6f7b5 Mon Sep 17 00:00:00 2001 From: BUDESCODE Date: Wed, 8 Jul 2026 14:47:00 +0100 Subject: [PATCH] Fix uncaught TypeError in onSortChanged when grid initializes with a sort AG Grid fires sortChanged from its async event queue during grid init when dashGridOptions.initialState.sort.sortModel is set, before the component's gridApi state has been assigned. onSortChanged was the only event handler dereferencing gridApi without a null guard, producing one uncaught 'Cannot read properties of null (reading isDestroyed)' error per grid on page load. Early-return when gridApi is null, matching the existing pattern in onFilterChanged. Fixes plotly/dash-ag-grid#466 --- CHANGELOG.md | 3 +++ src/lib/fragments/AgGrid.react.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe2e872..b2278153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D ## [unreleased] +### Fixed +- [#466](https://github.com/plotly/dash-ag-grid/issues/466) fix uncaught TypeError in `onSortChanged` when the grid initializes with a sort in `initialState` + ## [33.3.3] - 2025-12-19 ### Fixed - [#408](https://github.com/plotly/dash-ag-grid/pull/408) fixed issue where the `columnState` would conflict with `columnDefs` updates diff --git a/src/lib/fragments/AgGrid.react.js b/src/lib/fragments/AgGrid.react.js index c8d900c7..6065a1bd 100644 --- a/src/lib/fragments/AgGrid.react.js +++ b/src/lib/fragments/AgGrid.react.js @@ -733,6 +733,9 @@ export function DashAgGrid(props) { }, [props.rowData, virtualRowData, getRowData, customSetProps]); const onSortChanged = useCallback(() => { + if (!gridApi) { + return; + } const {rowModelType} = props; const propsToSet = {}; if (rowModelType === 'clientSide') {