fix: isolate user overlay callbacks in draw path - #833
Open
NemeZZiZZ wants to merge 1 commit into
Open
Conversation
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.
Problem
The three overlay figure callbacks —
createPointFigures,createXAxisFigures,createYAxisFigures— are user-supplied code (custom overlay templates). They areinvoked during drawing with no isolation:
If the callback throws, the exception propagates up through
_drawOverlay→updatePane→_layout, breaking the whole draw pass. A realistic case: overlaysrestored from persisted state (local storage / cloud) can end up with an invalid
point set, and a custom template that assumes valid input throws
(
TypeError: Cannot read properties of undefined (reading 'length')atcreatePointFigures). One broken overlay then breaks drawing for the chart, and —combined with the layout pending flag not being released on throw — freezes it entirely.
Indicator callbacks already have this isolation:
IndicatorImp.calcImp(
src/component/Indicator.ts) wraps the usercalccallback intry { … } catch { … },so a broken indicator fails alone instead of breaking the chart. The overlay
callbacks deserve the same treatment.
Fix
Wrap each of the three invocations and fall back to an empty figure list:
Same for
createXAxisFigures(OverlayXAxisView) andcreateYAxisFigures(
OverlayYAxisView). A throwing overlay now simply draws nothing for that passinstead of breaking the draw pipeline — mirroring the
calcImpbehaviour for indicators.Verification
pnpm code-lint— pass (154 files, no fixes)pnpm type-check— passpnpm build-esm— passmain:registerOverlaya template whosecreatePointFiguresthrows, create one, trigger a redraw — drawing breaks; with this patch the rest
of the chart keeps drawing correctly and the overlay is skipped.
Notes
calcImpisolationstyle. Logging the error could be added separately if wanted.
_layoutPendingwhen_layout()throws (fix: reset layout pending flag when layout throws #832) —each addresses one half of the "one bad overlay freezes the chart" failure.