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

Abierto
#187 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
react, typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
870
Forks
57
Merge medio
11 h 58 min
PR fusionados (30 d)
18

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/charts

Todos los issues de TanStack/charts

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.