Skip to content

fix(runtime): handle css variables in Style removeProperty and getPropertyValue - #19509

Open
kwy404 wants to merge 1 commit into
NervJS:mainfrom
kwy404:fix/runtime-style-css-variable-remove
Open

kwy404 wants to merge 1 commit into
NervJS:mainfrom
kwy404:fix/runtime-style-css-variable-remove

Conversation

@kwy404

@kwy404 kwy404 commented Sep 26, 2026 •

Copy link
Copy Markdown

这个 PR 做了什么? (简要描述所做更改)

Root cause: Style#setProperty stores a CSS variable such as --main-color under its original name, but removeProperty and getPropertyValue always pass the name through toCamelCase, which turns --main-color into MainColor. The lookup never matches, so:

  • style.getPropertyValue('--main-color') returns '' (also noted in Taro Next 在微信小程序中无法用 js 设置 css variable #7436)
  • style.removeProperty('--main-color') and style.setProperty('--main-color', null) do nothing
  • setting style.cssText (which setAttribute('style', ...) and removeAttribute('style') also do) keeps old variables, because the setter clears the previous properties through removeProperty. After style.cssText = 'color: red;' the style is still --main-color: blue; color: red;

Fix: skip toCamelCase for names starting with --, using the existing isCssVariable helper that cssText already uses. Other property names are unchanged.

Test: a new css variables case in packages/taro-runtime/tests/style.spec.ts. On main it fails with expected '' to be 'red' (and the cssText assertion alone fails with expected '--main-color: blue; color: red;' to be 'color: red;'). With the fix it passes, and pnpm --filter @tarojs/runtime run test passes (134 tests).

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

Summary by CodeRabbit

  • Bug Fixes
    • 修复 CSS 自定义属性名称被转换的问题。现在可以正确设置、读取和移除以 -- 开头的属性,同时普通样式属性仍按原有方式处理。

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4b8ee37f-e3be-4082-a6b4-552afc98d08c

📥 Commits

Reviewing files that changed from the base of the PR and between 36fc9e5 and 5af2965.

📒 Files selected for processing (2)
  • packages/taro-runtime/src/dom/style.ts
  • packages/taro-runtime/tests/style.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

Style.removeProperty 和 Style.getPropertyValue 现在保留 CSS 自定义属性名称。普通属性仍转换为驼峰形式。新增测试覆盖变量的设置、读取、移除和普通 cssText 序列化。

Changes

CSS 自定义属性处理

Layer / File(s) Summary
保留自定义属性名称
packages/taro-runtime/src/dom/style.ts, packages/taro-runtime/tests/style.spec.ts
读取和移除 CSS 自定义属性时保留原名称,普通属性仍转换为驼峰形式。测试检查变量的设置、读取和移除,并验证普通 cssText 的序列化结果。

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 5af29

CSS custom-property reads, removals, and style replacement now retain the original names. No concrete merge-blocking risk remains; the change is ready for normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 5af29

The fix makes CSS custom-property removal and lookup consistent with how those properties are stored. It introduces no identified new privilege or security boundary. Callers beyond the assessed runtime code remain uncertain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The established effect is limited to Style property state and its existing owning-element update path. The available evidence does not establish downstream callers or a broader attacker-controlled route.

Trust Boundaries and Controls

  • inferred — The assessed change does not add an identified trust or identity transition: custom-property writes were already accepted, and removal still uses the existing state mutation path. This does not establish the security properties of unexamined callers.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更,即修复运行时 Style 对 CSS 自定义属性在 removeProperty 和 getPropertyValue 中的处理。表述清晰且具体。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

兔子轻敲小键盘,
双短横线稳稳保留。
颜色设下又读出,
移除时原值归手。
普通样式排好队,
CSS 文本清清爽爽。

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

1 participant