Skip to content

Guard against null gridApi in onSortChanged#467

Open
SAY-5 wants to merge 1 commit into
plotly:mainfrom
SAY-5:fix-sortchanged-null-gridapi
Open

Guard against null gridApi in onSortChanged#467
SAY-5 wants to merge 1 commit into
plotly:mainfrom
SAY-5:fix-sortchanged-null-gridapi

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 18, 2026

Copy link
Copy Markdown

Fixes #466.

onSortChanged is the only grid event handler that dereferences gridApi without a null check. When a grid is created with a sort applied at init time (via initialState.sort.sortModel), AG Grid queues the sortChanged event during grid creation and flushes it on a setTimeout tick that can run before React commits the setGridApi update from onGridReady. The closure then sees gridApi === null and gridApi.isDestroyed() throws an uncaught TypeError.

This aligns the guard with every sibling handler (onPaginationChanged, onRowDataUpdated, etc.), which already use if (gridApi && !gridApi?.isDestroyed()).

The same handler is also bound to onRowDragEnd, so the guard covers that path too.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught TypeError "Cannot read properties of null (reading 'isDestroyed')" in onSortChanged when a grid initializes with initialState sortModel

1 participant