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

未关闭
#431 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript
领域
frontend, testing

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
TypeScript
星标
145
派生
12
平均合并
1 天 14 小时
30 天内合并 PR
43

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

gravity-ui/graph 的其他 Issue

查看 gravity-ui/graph 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。