Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react组件中的style属性使用css变量时,值会被自动添加上"px"单位,初步排查是@tarojs/react 的setStyle逻辑有问题 #12617

Closed
febear opened this issue Oct 8, 2022 · 0 comments
Assignees
Labels
bug Something isn't working F-react Framework - React good first issue Good for newcomers T-alipay Target - 编译到支付宝小程序 V-3 Version - 3.x
Milestone

Comments

@febear
Copy link

febear commented Oct 8, 2022

相关平台

支付宝小程序

小程序基础库: 最新版本
使用框架: React

复现步骤

使用@tarojs/react@3.5.6库, 任意渲染一下<div style={{ lineHeight: 3, '--item-span': 2 }}>,小程序运行时会自动变成'--item-span': 2px

期望结果

组件中的sytle属性的css变量不希望自动添加px

实际结果

组件中的sytle属性的css变量自动添加px

环境信息

👽 Taro v3.5.3


  Taro CLI 3.5.3 environment info:
    System:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 14.17.3 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 6.14.13 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: ^3.4.13 => 3.5.4
      @tarojs/components: ^3.4.13 => 3.5.4
      @tarojs/components-react: ^3.5.5 => 3.5.5
      @tarojs/helper: ^3.4.13 => 3.5.4
      @tarojs/mini-runner: ^3.4.13 => 3.5.4
      @tarojs/plugin-framework-react: ^3.4.13 => 3.5.4
      @tarojs/plugin-html: ^3.4.13 => 3.5.4
      @tarojs/plugin-platform-alipay: ^3.4.13 => 3.5.4
      @tarojs/plugin-platform-jd: ^3.4.13 => 3.5.4
      @tarojs/plugin-platform-qq: ^3.4.13 => 3.5.4
      @tarojs/plugin-platform-swan: ^3.4.13 => 3.5.4
      @tarojs/plugin-platform-tt: ^3.4.13 => 3.5.4
      @tarojs/plugin-platform-weapp: ^3.4.13 => 3.5.4
      @tarojs/react: ^3.4.13 => 3.5.4
      @tarojs/router: ^3.4.13 => 3.5.4
      @tarojs/runtime: ^3.4.13 => 3.5.4
      @tarojs/shared: ^3.4.13 => 3.5.4
      @tarojs/taro: ^3.4.13 => 3.5.4
      @tarojs/taro-h5: ^3.4.13 => 3.5.4
      @tarojs/webpack-runner: ^3.4.13 => 3.5.4
      babel-preset-taro: ^3.4.13 => 3.5.4
      react: ^17.0.0 => 17.0.2

补充信息

具体代码位置:

function setStyle (style: Style, key: string, value: string | number) {

代码思路:
if (key[0] === '-') {
//判断了【-】的前缀时,则自动将value转换成字符串,但下方isNumber使用的不是最新值 style[key]而是传递值value,是否考虑这里直接return回去就好了
style.setProperty(key, value.toString());
}
style[key] =
isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
? value 'px'
: value == null
? ''
: value;

@taro-bot2 taro-bot2 bot added F-react Framework - React T-alipay Target - 编译到支付宝小程序 V-3 Version - 3.x labels Oct 8, 2022
@Chen-jj Chen-jj self-assigned this Oct 9, 2022
@Chen-jj Chen-jj added good first issue Good for newcomers bug Something isn't working labels Oct 17, 2022
@Chen-jj Chen-jj added this to the 3.5.7 milestone Oct 17, 2022
@Chen-jj Chen-jj closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working F-react Framework - React good first issue Good for newcomers T-alipay Target - 编译到支付宝小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants