-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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 15+ inline styling is producing concatenated style properties from separate, unique object keys #6524
Comments
@nathanmarks We already faced a similar issue on the Material-UI Repository, we ended up fixing it with mui/material-ui#3124. I'm wondering if this isn't the same issue. |
@oliviertassinari I tested with React 0.14 and React 15 with a very simple component: const Example extends React.Component {
render () {
const styles = {
background: 'none',
backgroundColor: 'red'
};
return (
<div style={styles}>Hello</div>
);
}
} And in the chrome dev tools inspect element styles panel, I saw different computed values for React 0.14 and React 15 |
Hmm, it could be that Object.assign is at play here. I didn't think that would matter on initial render at least (I don't think we use a copy of the style object) but I'm just skimming this code path. It would make sense that the order is getting screwed up and red gets set before none. The computed values are going to be misleading due to the use of createElement. In 14 we generated a string of markup for initial render which would look like In 15 we create a DOM node and then set each style, just like we would do for updates in 14 and below. So So what would be interesting is if you followed the same steps as React is doing in both versions of Chrome and see what happens. http://jsbin.com/dekiyulane/edit?html,js,output |
Strangely I'm having difficulty reproducing this again using my simple example component (and your example), I wonder if I clicked out of browserstack before it had a chance to finish rendering completely. So @oliviertassinari may well have been correct with the I'm going to do some further testing -- if I end up swinging back around to React again I'll reopen this issue. Thanks for the explanation by the way, definitely helps understand the initial render output 👍 |
The Object.assign issue has been pretty random and inconsistent in my experience. Thanks for checking! |
Figured it out. Object property iteration order is ending up different in The result is Now, since object property iteration order can't be guaranteed (from what I understand). That means this is definitely something we need to solve when we generate inline styles. |
Assume the following styles object is provided to a component:
Prior to v15, this would result in (in the browser's computed styles):
In React 15+, this results in (in chrome 49+):
In chrome 48 it results in:
What this means is in chrome 49+, it has a red background, but in chrome 48 it has no background.
I'm not entirely sure who/what is at fault here. Would you be able to shed some light on the change? Is this a bug or an intended feature?
The text was updated successfully, but these errors were encountered: