Custom property style bindings ignore static and `[style]` values of same name since 22.1

未关闭
#71,806 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
frontend

调研方向

Start with the compiler package and the compliance golden at style_bindings/css_custom_properties.js, which shows the differing keys for custom properties. Trace how style priority looks up values when [style.--x] is combined with static style or [style], then add regression coverage for the reported cases. Done when the bound custom property preserves the static or [style] value when its binding is undefined and the regression tests pass.

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

描述

area: compiler
Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes, works in 22.0.8, broken in 22.2.4 and 22.3.0-next.3. Came with #68846

Description

Hit this in my ui lib, had to move component inputs to separate variable

[style.--x] compiles to key --%NS%x, but static style="--x: red" and [style]="'--x: red'" keep --x. Styling priority looks values up by key, so these never mathc and binding stops seeing value of same name. [style.color] is not affected. No provideCssVarNamespacing() needed to hit this

  • host binding [style.--x] now overwrites value author set on component element, before author won
  • undefined no longer falls back to static or [style] value, element ends up without --x
case bound value 22.0.8 22.2.4 same case with color, 22.2.4
<my-cmp style="--x: red"> + host [style.--x] blue --x: red --x: blue color: red
<my-cmp style="--x: red"> + host [style.--x] undefined --x: red empty color: red
<i style="--x: red" [style.--x]="v"> undefined --x: red empty color: red
<i [style]="'--x: red'" [style.--x]="v"> undefined --x: red empty color: red
host style: '--x: red' + host [style.--x] undefined --x: red empty color: red

With provideCssVarNamespacing('ns') both stay on element: --x: red; --ns_x: blue

Please provide a link to a minimal reproduction of the bug
@Component({ selector: 'my-cmp', template: '', host: { '[style.--x]': 'v' } })
class MyCmp {
  @Input() v?: string;
}

@Component({ selector: 'app-root', imports: [MyCmp], template: `<my-cmp style="--x: red" v="blue" />` })
class App {}

getAttribute('style') on my-cmp: --x: red in 22.0.8, --x: blue in 22.2.4 and 22.3.0-next.3

Please provide the exception or error you saw

None

Please provide the environment you discovered this bug in (run ng version)

@angular/core 22.0.8, 22.2.4 and 22.3.0-next.3, Chromium, JIT

Anything else?

Compliance golden style_bindings/css_custom_properties.js shows same split: --camel-case in consts, --%NS%camelCase in ɵɵstyleProp

主要语言
TypeScript
星标
101k
派生
28.2k
平均合并
2 天 45 分钟
30 天内合并 PR
373

环境准备

从这里开始

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

angular/angular 的其他 Issue

查看 angular/angular 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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