-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Props 传递 Class 渲染异常 #4059
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
CC @Chen-jj |
@sheyunsi CLI 和依赖版本保持一致。 这样的 log 有问题? |
@Chen-jj 您上面发的log是没有问题的,但是我这边测试的还是有问题,我贴下我的log: 想知道您那边也是 1.3.11 或 1.3.12 吗? |
@sheyunsi 我本地开发所以是 link 来用的,一直保持最新版。你可以删 node_modules 重装试试。 |
@Chen-jj 我删了重装过了,还是这样。您看如果方便的话,我可以打个包,把代码发给您看看。 |
@sheyunsi 也行吧,你把代码精简下放 github。建议再试试新建一个项目,跑你的这段代码试试。 |
Hello~ 您的问题我们无法复现。如果有空的话还请拔冗提供一个简单的复现 demo,否则这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
@sheyunsi 老哥我今天再尝试了一下可以复现了。之前图快没有使用 Product 类构建 this.state.source,而是直接写的对象字面量。 debug 后发现,是一个较神奇的问题。Taro 为了减少每次 setData 的量,会先 diff 将要 setData 的数据和当前组件的 data 数据,然后再按路径去 setData。 然后我尝试了三种思路,能绕过问题:
猜测小程序底层虚拟 dom 的 diff 会影响到 props 的数据。 暂时没有什么好的解决办法,去掉 diff 肯定和对 diff 数据做深拷贝对性能都有很大影响,所以建议换用对象字面量。 |
已修复 |
问题描述
父组件使用
map
渲染一个数组,数组中的元素都是class
,子组件在接受到props
以后能正常渲染。 但是当这个数组被重新排序以后,子组件的渲染就出现问题了,并且还修改了父组件的state
。复现步骤
[复现问题的步骤]
Shuffle
对this.state.source
进行重新排序;setState
之后的数据 和 渲染完之后的数据并不一样,子组件在渲染的过程中,把父组件的state
给修改了。父组件:
子组件:
系统信息
👽 Taro v1.3.11
Taro CLI 1.3.11 environment info:
System:
OS: macOS 10.14.5
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.4.0 - ~/.nvm/versions/node/v12.4.0/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v12.4.0/bin/npm
npmPackages:
@tarojs/components: 1.3.9 => 1.3.9
@tarojs/plugin-babel: 1.3.9 => 1.3.9
@tarojs/plugin-csso: 1.3.9 => 1.3.9
@tarojs/plugin-less: 1.3.9 => 1.3.9
@tarojs/plugin-uglifyjs: 1.3.9 => 1.3.9
@tarojs/router: 1.3.9 => 1.3.9
@tarojs/taro: 1.3.9 => 1.3.9
@tarojs/taro-alipay: 1.3.9 => 1.3.9
@tarojs/taro-h5: 1.3.9 => 1.3.9
@tarojs/taro-swan: 1.3.9 => 1.3.9
@tarojs/taro-tt: 1.3.9 => 1.3.9
@tarojs/taro-weapp: 1.3.9 => 1.3.9
@tarojs/webpack-runner: 1.3.9 => 1.3.9
eslint-config-taro: 1.3.9 => 1.3.9
eslint-plugin-taro: 1.3.9 => 1.3.9
nerv-devtools: ^1.4.0 => 1.4.3
nervjs: ^1.4.0 => 1.4.3
stylelint-config-taro-rn: 1.3.9 => 1.3.9
stylelint-taro-rn: 1.3.9 => 1.3.9
补充信息
经过排查,可以确定是在传进
props
后被修改的,可以在子组件的componentWillReceiveProps
中查看。如果将
props
序列化之后再传递的是可以的。The text was updated successfully, but these errors were encountered: