[v2] Port additional CSS variable observation from PR #430

Abierto
#431 0 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
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
react, typescript
Área
frontend, testing

Línea de trabajo

Start in packages/graph-css-variables and read the current CSSVariablesLayerProps implementation and observer tests, then compare the reviewed behavior in PR #430. Add coverage for custom variable reads, updates, subscription changes, and equal-list updates; the issue also names apps/storybook/src/stories/plugins/cssVariables for the example. Done means the listed unit and browser cases, package documentation, and declarations meet the acceptance criteria.

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

Descripción

Goal

Port the additionalCSSVariables capability from #430 to the v2 branch so applications can observe their own CSS variables and use onChange to update custom graph components, such as group colors.

The target is @gravity-ui/graph-css-variables (packages/graph-css-variables), extracted in #402. Adapt the final reviewed behavior of #430 to the current v2 implementation.

Scope

  • Add additionalCSSVariables to the public CSSVariablesLayerProps.
  • Observe custom names alongside built-in variables, including initial reads and subsequent change notifications.
  • Report custom values through onChange; keep built-in graph color/constant mappings unchanged. Custom-only updates must not call graph.setColors() or graph.setConstants().
  • Support replacing and clearing the list: newly added names become observable, removed names stop producing notifications, and unregistered names are filtered out.
  • Apply subscription changes using the updated props and clean up the previous observation correctly.
  • Preserve v2's proxy-based observation, unset-value handling, and oldValue tracking. Cover variables that are initially unset and become defined later.
  • Keep the implementation and public exports in graph-css-variables, with React usage through @gravity-ui/graph-react.

Carry over the notification-loop fix

The version of #430 reviewed at e0cf28109b70e9cff10d36ea8a6a2f5a2d9182bb compares the additional-variable array by reference. An inline array combined with a callback that updates React state causes repeated observer restarts and initial notifications while CSS remains unchanged.

See the confirmed reproduction and minimal fix.

Compare the variable list by contents, treating an omitted list as empty; the existing lodash/isEqual dependency is sufficient for the minimal fix. Replacing the list with an equal array must not restart observation or emit another initial notification.

Acceptance criteria

  • Unit tests cover initial custom values, subsequent changes, built-in mapping preservation, filtering, list replacement/clearing, and cleanup.
  • A regression test covers an equal new array and a React consumer with inline additionalCSSVariables and an onChange callback that stores the received records in state. Notifications settle after the initial read and resume only for actual value or subscription changes.
  • Browser coverage with the real observer verifies custom-variable updates and the initially-unset → defined transition without regressing v2's existing unset-value behavior.
  • Port the custom-variable Storybook example to apps/storybook/src/stories/plugins/cssVariables, using v2 package imports. Changing the variable updates the existing group's color without replacing its component.
  • Update the package documentation and verify that the public prop is available through the published package declarations.
  • The affected package's type checks, lint, tests, and relevant package-contract checks pass.
Lenguaje dominante
TypeScript
Estrellas
145
Forks
12
Merge medio
1 d 14 h
PR fusionados (30 d)
43

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 gravity-ui/graph

Todos los issues de gravity-ui/graph

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.