fix(model): guard against null data in getDataParams and event handler#21537
Open
davesecops wants to merge 1 commit intoapache:masterfrom
Open
fix(model): guard against null data in getDataParams and event handler#21537davesecops wants to merge 1 commit intoapache:masterfrom
davesecops wants to merge 1 commit intoapache:masterfrom
Conversation
|
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. |
This was referenced Mar 11, 2026
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():Related test cases
Added
test/ut/spec/model/getDataParams.test.ts— 5 test cases covering pie, treemap, funnel, sunburst, and tree series. Each test mocksgetData()to return null and verifiesgetDataParams()does not throw.All existing tests continue to pass (the 1 pre-existing failure in
time.test.ts:roundTime_localeis a DST-dependent issue onmaster, unrelated to this PR).Document Info
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
See
test/ut/spec/model/getDataParams.test.ts— 5 unit tests covering all guarded chart types.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 source files + 1 test file), safe (returns empty params matching existing fallback patterns), and follows internal precedent.