Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

auto alias className to class will make props trustless #422

Closed
paranoidjk opened this issue Sep 7, 2017 · 4 comments
Closed

auto alias className to class will make props trustless #422

paranoidjk opened this issue Sep 7, 2017 · 4 comments

Comments

@paranoidjk
Copy link

paranoidjk commented Sep 7, 2017

Reproducible demo: https://codepen.io/paranoidjk/pen/MvdLpd

This is caused by #412, it breaks our code base, please revert it.

The reason is preact-compat add a extra alias attribute class to component props when it has className attribute.

But in some case, we will want to omit className and pass rest props to child component, in this case, child component will got a unexpected class attribute.

I think preact-compat can not require users to delete class and for when they want to omit className, htmlFor, since preact-compat goal is to compatibility with react but no need to change users code when they want to switch form react to preact.

@paranoidjk
Copy link
Author

cc @developit

@paranoidjk paranoidjk changed the title auto alias className to class will makes props trustless auto alias className to class will make props trustless Sep 7, 2017
paranoidjk added a commit to ant-design/ant-design-mobile that referenced this issue Sep 7, 2017
@developit
Copy link
Member

What if we made it non-enumerable?

@paranoidjk
Copy link
Author

@developit It probably ok. Since we normally won't access props.class directly in react codebase, and babel will compile spread operator to use Object.assign or a polyfill with for in, in this case it should works fine .

But i am not sure it will be 100% safe. So i think there is a tradeoff.

IMO, i suggest preact-compat avoid to pollute users component props object in runtime, it's a little dangerous.

@marvinhagemeister
Copy link
Member

I'm unable to reproduce the described issue with Preact X anymore 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants