Skip to content

fix(highcharts): keep tooltip formatter override stable across re-renders#894

Merged
korvin89 merged 2 commits into
mainfrom
fix/highcharts-tooltip-formatter-mutation
Jun 15, 2026
Merged

fix(highcharts): keep tooltip formatter override stable across re-renders#894
korvin89 merged 2 commits into
mainfrom
fix/highcharts-tooltip-formatter-mutation

Conversation

@korvin89

@korvin89 korvin89 commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

A custom libraryConfig.tooltip.formatter stops working after the first render. It became reliably reproducible after upgrading React 17 → 19: React 18+ StrictMode double-mounts components in dev (mount → unmount → remount), and the override silently falls back to the default ChartKit tooltip.

Root cause

prepareConfig was mutating the caller's libraryConfig:

params.tooltip.formatter = function (tooltip) {
    return `<div class="${b()}">${formatter.call(this, tooltip)}</div>`;
};
delete options.highcharts.tooltip.formatter; // ← deletes from the user's libraryConfig

options.highcharts is the consumer's libraryConfig (passed by reference, no clone). The wrapping works once, but the delete strips tooltip.formatter off the shared object. Any later config build that reuses the same libraryConfig reference — StrictMode double-mount, splitTooltip toggle, a data update reusing the same config, a second chart — no longer finds the formatter and renders the default tooltip.

It's a latent impurity in getDerivedStateFromProps; React 18+ StrictMode just surfaced it (exactly what it's designed to do). The StrictMode trigger is dev-only, but production triggers (data updates / splitTooltip / shared config) hit the same bug.

Fix

Don't mutate the input. The raw formatter is removed from the clone (preparedHighchartsOptions, which merge({}, …) already creates) right before the final mergeWith, so the wrapped formatter on params survives and libraryConfig is left untouched.

…ders

prepareConfig no longer mutates the caller's libraryConfig: the raw
tooltip.formatter is stripped from a clone (preparedHighchartsOptions)
instead of from the input object. A custom libraryConfig.tooltip.formatter
now survives repeated config builds — e.g. React 18+ StrictMode
double-mount, which surfaced this regression after a React 17 -> 19 upgrade.

Adds regression tests at the prepareConfig level and at the component
level (rendering under <StrictMode>); both assert the formatter survives
and libraryConfig is not mutated.
@gravity-ui-bot

Copy link
Copy Markdown
Contributor

Preview is ready.

@korvin89 korvin89 force-pushed the fix/highcharts-tooltip-formatter-mutation branch from c9a8858 to 2ad152a Compare June 13, 2026 11:01
@korvin89

Copy link
Copy Markdown
Collaborator Author

/update-screenshots

@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 18.64% 286 / 1534
🔵 Statements 18.73% 296 / 1580
🔵 Functions 14.5% 48 / 331
🔵 Branches 12.95% 149 / 1150
File CoverageNo changed files found.
Generated in workflow #213 for commit 5453e3f by the Vitest Coverage Report Action

@gravity-ui-bot

gravity-ui-bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

🎭 Tests Report is ready.
🎭 Coverage Report is ready.

@korvin89 korvin89 force-pushed the fix/highcharts-tooltip-formatter-mutation branch from 13dc3d2 to 2ad152a Compare June 13, 2026 11:19
@korvin89

Copy link
Copy Markdown
Collaborator Author

Falling tests will be fixed here #895, and they are not related to current changes

@korvin89 korvin89 marked this pull request as ready for review June 15, 2026 08:45
@korvin89 korvin89 requested a review from kuzmadom as a code owner June 15, 2026 08:45
kuzmadom
kuzmadom previously approved these changes Jun 15, 2026
The Base/SplitTooltip visual tests snapshot before @gravity-ui/charts finishes its
async render, so they flake in CI (blank-canvas capture). Skip them until the timing
race and the withSplitPane reflow issue are fixed. Tracked in #896.
@korvin89 korvin89 merged commit c9abd09 into main Jun 15, 2026
5 checks passed
@korvin89 korvin89 deleted the fix/highcharts-tooltip-formatter-mutation branch June 15, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants