Skip to content

Guard against null gridApi in onSortChanged#467

Merged
BSd3v merged 3 commits into
plotly:v35from
SAY-5:fix-sortchanged-null-gridapi
Jun 24, 2026
Merged

Guard against null gridApi in onSortChanged#467
BSd3v merged 3 commits into
plotly:v35from
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>
@AnnMarieW AnnMarieW requested a review from BSd3v June 22, 2026 18:05
@AnnMarieW

Copy link
Copy Markdown
Collaborator

Hi @SAY-5

Thanks for the PR! Odd that so many tests fail. It might be worth switching to v35 branch and see if it works there.

@BSd3v BSd3v changed the base branch from main to v35 June 22, 2026 19:23
@BSd3v BSd3v merged commit 0eab401 into plotly:v35 Jun 24, 2026
6 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@AnnMarieW

Copy link
Copy Markdown
Collaborator

Thanks for the PR @SAY-5

💃

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

4 participants