fix(model): guard against null data in getDataParams and event handler#21536
Closed
davesecops wants to merge 1 commit intoapache:masterfrom
Closed
fix(model): guard against null data in getDataParams and event handler#21536davesecops wants to merge 1 commit intoapache:masterfrom
davesecops wants to merge 1 commit intoapache:masterfrom
Conversation
When a series is disposed (component unmount, setOption with notMerge,
toolbox restore), getData() can return null — as acknowledged by the
comment in SeriesModel.getData(). However, getDataParams() and its
overrides unconditionally access properties on the result, causing
TypeErrors when mouse events fire on stale DOM elements after disposal.
This fix adds null guards at three levels:
1. DataFormatMixin.getDataParams() base method — returns {} when
getData() is null, protecting all callers (tooltips, labels, etc.)
2. Event handler in echarts.ts — wraps getDataParams() call in
try/catch, protecting against crashes in any chart override
3. All 6 chart-specific getDataParams() overrides — each now checks
getData() before accessing chart-specific properties (.tree,
.mapDimension, .getGraph, etc.)
Fixes apache#9402, apache#16998
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
Author
|
Superseded by #21537 (branch renamed to follow project convention |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Information
This pull request is in the type of:
What does this PR do?
Adds null guards to
getDataParams()and its 6 chart-specific overrides to prevent TypeErrors whengetData()returns null on disposed series during mouse events.Fixed issues
Details
Before: What was the problem?
When a chart series is disposed (via
echarts.dispose(), component unmount in React/Vue/Angular,setOptionwithnotMerge, or toolbox restore),SeriesModel.getData()returnsnull/undefined. The comment inSeries.tsexplicitly acknowledges this:However,
getDataParams()and its overrides unconditionally call methods on the result:The primary crash trigger is the event handler in
echarts.tswhich callsgetDataParams()duringmousemove/mouseoutevents that fire on stale DOM elements after chart disposal. This affects all chart types in all frameworks where component lifecycle causes disposal during user interaction.After: How does it behave after the fixing?
Three layers of defense:
1. Base method guard (
src/model/mixin/dataFormat.ts):Returns
{}when data is null — consistent with the existing fallback atecharts.ts:778(dataModel.getDataParams(...) || {}). Protects all callers outside the event handler (tooltips, labels, visual pipeline).2. Event handler guard (
src/core/echarts.ts):Wraps the highest-risk call site in try/catch, catching crashes from any chart override's
getData()access.3. Override guards (6 chart series files):
Each override now checks
getData()before accessing chart-specific properties:TreemapSeries.ts— guardsdata.treeaccessSunburstSeries.ts— guardsdata.treeaccessTreeSeries.ts— guardsdata.treeaccessPieSeries.ts— guardsdata.each(),data.mapDimension()accessFunnelSeries.ts— guardsdata.mapDimension(),data.getSum()accessChordSeries.ts— guardsdata.getName(),this.getGraph()accessThis pattern follows existing precedent in the codebase —
SeriesModel.getAllData()already null-guardsgetData():Document Info
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
N/A — this is a defensive fix. A test case would require simulating chart disposal during mouse events (component unmount race condition).
Merging options
Other information
This bug has been open since 2018 (#9402) and affects all chart types. It is the most commonly reported ECharts crash in React/Vue applications where charts are rendered in routed views. The fix is minimal (35 lines added across 8 files), safe (returns empty params matching existing fallback patterns), and follows internal precedent.