Conversation
When `options.filter` rejected every active element, `update()` still took the visible branch because it only checked `active.length`. The title, body and footer callbacks were then invoked with an empty TooltipItem array, which broke callbacks that reasonably assume at least one item. Build the items first and branch on the filtered result instead, so a tooltip with nothing left to show is treated like one with no active elements: the callbacks are skipped and the tooltip stays hidden.
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.
Fixes #12274
The problem
Tooltip#update()decided whether the tooltip had anything to show by looking atthis._active:options.filteris applied inside_createItems, after that branch is chosen. So when a filter rejects every active element there are still active elements, the visible branch runs, andgetTitle/getBody/getFooterare invoked with an emptyTooltipItem[].That breaks callbacks which reasonably assume at least one item — as reported, users have to add a guard to their
titlecallback that is unnecessary in every other situation.The change
Build the items first, then branch on the filtered result. A tooltip with nothing left to show is now treated the same as one with no active elements: callbacks are skipped and it stays hidden.
_createItemsis still called exactly once per update, and is still skipped entirely when there are no active elements, sodataPoints/labelColorskeep their existing lifecycle.Verification
Added a regression test that filters out every item and asserts the
titlecallback is never invoked and the tooltip stays atopacity: 0.I ran the full CI suite on a fork before opening this (
workflow_dispatchon the branch), and the same suite on unmodifiedmasteras a baseline:master(baseline)controller.polarArea/pointLabels/overlapping.js, FirefoxThat single failure is a pre-existing pixel fixture on Firefox and is present without this change. Windows is fully green on both.