Repository navigation
fix: skip missing active elements when setting hover - #12411
Conversation
kurkle
left a comment
There was a problem hiding this comment.
Thanks, this is the right fix for the chart side. I ran it on current master: the new spec fails without the change, and these all throw Cannot set properties of undefined (setting 'active') on master and work with it:
- an index past the end of the data, e.g.
chart.setActiveElements([{datasetIndex: 0, index: 99}])(throws right away on master, not only on the next update) - the same together with a valid point, followed by
update() hover.mode: 'dataset'with an invalid first item
Two requests before this goes in:
1. The tooltip has the same gap. Tooltip.setActiveElements() builds its list the same way and keeps the entries without an element, so this still throws after this change:
chart.tooltip.setActiveElements([{datasetIndex: 0, index: 99}], {x: 0, y: 0});
chart.update();
// TypeError: Cannot read properties of undefinedThe docs sample calls both methods with the same list, so an invalid index would still take the chart down through the tooltip. Could you apply the same filter there in this PR, with a spec?
2. A spec for the out-of-range index. The current spec covers a dataset that hasn't been built yet. The more common case is an index that doesn't exist in an existing dataset (for example when hover is synced from another chart with more data). That one throws inside setActiveElements itself on master, so it is worth pinning separately.
One thing to be aware of, not a request: a point in a dataset that is added but not yet updated is now dropped for good, so it is not active after the update() either. That is better than the crash, and fine for this PR.
👷 Deploy request for chartjs-docs pending review.Visit the deploys page to approve it
|
|
Thanks for catching the tooltip case. |
Summary
Calling
setActiveElementsafter adding a dataset but before callingupdate()can store an undefined element. The next update throws when it reapplies hover styles.Fixes #12042
Evidence
chart.update()throwsCannot set properties of undefined (setting 'active').The controller suite passed in Chrome and Firefox. Lint, type checks and integration tests passed. The full browser suite had the same 13 image fixture failures on this branch and on
masteron macOS.Merge Danger
Door Two-way. Blast radius Hover.