[Perf] Tooltip: every move re-renders the React chart, builds unused default content and rewrites unchanged attributes

Aperta
#187 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
react, typescript

Direzione di ricerca

The issue bundles five separate tooltip gaps, so pick one section rather than all five. Start with hide() in packages/charts-core/src/tooltip.ts and the exit cancel path in packages/charts-core/src/motion.ts, using the fake Element.animate repro. Done when the exit is no longer cancelled by repeated hide calls and the repro shows 0 cancel calls. The design proposals (external store, per-phase motion, data-state attributes, delays) need maintainer input before implementation.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version: @tanstack/charts 1.1.0 (57774e1).

With a custom tooltip body (and with the motion() renderer for F), each pointer move that changes the tooltip does work no one sees: the React adapter re-renders the chart (A), core builds the default content the custom body replaces (E), and paint rewrites attributes that did not change (F). Related: #179 (only the default tooltip duration).

Paths are under packages/; links pin commit 57774e14a1a86081eddb3a23523724a40da05640.

A. Tooltip target state re-renders the chart (react-charts)

  • useTooltipBody keeps the target in React.useState; onChange calls setTarget (tooltip.tsx:152-159).
  • Each render rebuilds hostOptions, so the layout effect calls adapter.update (RendererChart.tsx:162-186). update refreshes DOM text metrics (renderer.ts:985-986).
  • Repro (vitest + jsdom, 4 pointer moves): expected 3 to be +0 calls to adapter.update.
  • Expected: a target change updates only the tooltip body. Proposed: keep the target in an external store read by a leaf component (useSyncExternalStore).
  • Downstream measurement (bklit migration, Chrome, core Chart + external store): pointermove p95 2-6x lower.

B. A repeated hide() restarts the exit

Moved to #209 (a bug, together with C).

C. Finished tooltip animations stay attached

Moved to #209.

D. First show cannot be styled or delayed

Moved to #210 (a feature, together with the per-phase motion proposed under B).

E. Default content is always built

  • paint always calls createChartTooltipContent before the custom body (tooltip.ts:117-124), and the result feeds the aria-label (:293).
  • Repro: an items[].text formatter is called 1 time per paint with a custom body, expected 0.
  • Expected: default content computed only when read. Proposed: resolve content lazily, or let a custom body supply the accessible label.
  • Downstream measurement (bklit migration, Chrome CDP profile, 300 moves): about 6 ms per 100 moves; grows with series count.

F. Each paint rewrites the tooltip element (from this comment)

  • On every move that repaints the tooltip, paint sets visibility: hidden and removes it again, and re-sets className, pointer-events, user-select and data-sticky, even when nothing changed (tooltip.ts:106-162). configureTooltipSemantics re-sets role, aria-live and aria-label.
  • The spring glide writes style.translate from requestAnimationFrame every frame (motion.ts:419-428, motion.ts:484-497). The tween glide uses WAAPI instead.
  • Measured (production build, sankey, MutationObserver on the tooltip, 60 moves): about 12 mutation records per move. About 4.7 are translate, 2.5 visibility, 3.75 the unchanged attributes, 1.8 content and 1 left/top.
  • Proposed: compare before writing in paint. Run the spring glide as a sampled WAAPI translate, like the tween path.
Lingua principale
TypeScript
Stelle
870
Fork
57
Merge medio
11h 58m
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/charts

Tutte le issue di TanStack/charts

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.