fix(tooltip): clear pending timers on dispose - #21733
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Open
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 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?
Clears the tooltip's pending
setTimeouthandles when the tooltip view is disposed, so a delayed callback can no longer run against a torn-down view and throw.Fixed issues
Details
Before: What was the problem?
When
tooltip.showDelayis greater than0, showing a tooltip schedules a timer inTooltipView#_showOrMove:TooltipView#disposenever cleared that handle, but it did reset the members the callback depends on:So if the chart is disposed while a
showDelaytimer is still pending — which is the normal case when a user hovers a chart and then the view is unmounted (React/Vue route change, tab switch,echarts.dispose()before re-init) — the callback fires afterwards and dereferences the nulled content:The error surfaces up to
showDelaymilliseconds after the chart is gone, so it is reported as a random uncaught exception rather than being traced back todispose. It reproduces with bothrenderMode: 'html'andrenderMode: 'richText', and with bothtrigger: 'item'andtrigger: 'axis'.Two smaller teardown leaks are in the same area:
_refreshUpdateTimeoutis also left pending. Its callback is guarded by!api.isDisposed()so it does not throw, but the timer keeps the disposed view reachable until it fires.TooltipRichContent#disposedoes not clear itshideDelaytimer, whileTooltipHTMLContent#disposealready does clear both of its timers.After: How does it behave after the fixing?
TooltipView#disposenow clears_showTimoutand_refreshUpdateTimeout, andTooltipRichContent#disposeclears_hideTimeoutto matchTooltipHTMLContent#dispose.The timers are cleared at the very top of
dispose, before theenv.node || !api.getDom()early return and before the members are nulled, so the cleanup cannot be skipped.Disposing a chart with a pending tooltip timer no longer throws, and no tooltip timer outlives the chart.
Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
Added
test/ut/spec/component/tooltip/dispose.test.ts, coveringshowDelayforhtml/richTextrender modes anditem/axistriggers, plus therichTexthideDelaytimer. Each case asserts that no tooltip timer is left pending afterdisposeand that running pending timers does not throw.Verified that the four
showDelaycases fail onmasterwithTypeError: Cannot read properties of null (reading 'setEnterable')and pass with this change.npm run test(27 suites / 199 tests),npx tsc --noEmit, andeslinton thechanged files all pass.
Merging options
Other information
While auditing this area I also noticed that
_showTimoutis not cleared inmanuallyHideTip, which is the separate problem reported in #16859 (closed asstale) and attempted in the unmerged #17499. That is a behavioural change rather
than a teardown fix, so it is intentionally left out of this PR.