-
Notifications
You must be signed in to change notification settings - Fork 47.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
CSS backgroundSize
property lost when re-rendering an image URL inside of an adjacent background
property
#5030
Comments
backgroundSize
property lost when re-rendering an image URL inside of a background
propertybackgroundSize
property lost when re-rendering an image URL inside of an adjacent background
property
This is a known issue with CSS shorthand expansion. For now the recommendation is to list each explicit property and not rely on the shorthand. Usually these bugs only surface on update because initial render simply creates an inline style as a part of setting innerHTML. Updates work on individual properties so when you set See #4661 for more discussion. |
background is shorthand for: background is NOT shorthand for backgroundSize. |
@zpao @spicyj @syranide Could we solve all these correctness issues/concerns if we were to use My understanding is that we've always claimed that diffing the css ourselves was faster than letting the browser do it, but Ben's perf test (http://jsperf.com/style-vs-csstext-vs-setattribute/8) from #929, on chrome, seems to indicate that |
Yes, but performance-wise that is near identical to setting each property individual like we do now, except we can cheaply skip unchanged properties, so you definitely do not want to do that for this reason. I could be proven wrong here, but that's the last I remember when messing around with it. |
Right, so if performance is nearly identical but the 'correctness' is easier (since we punt to the browser), it seems like a pure win. We could still cheaply skip if all the properties are unchanged, which covers the common case. Based on my reading: It seems to me that the performance difference of |
With |
Yeah, that's true, I don't have the numbers, but if we are already updating a css property on that element (ie. repainting that element anyway), I suspect that the additional cost of parsing a couple additional properties out of a If it is in fact a wash, then I argue that |
Please move any discussion about |
use code follow:
|
The CSS
background
property can shorthanded in many various ways. When inlining multiple styles including that property, React seems to optimize them on re-render.For example, if we define a style like so:
The initial render returns a style in the form:
style="background:#ffffff url([URL]);background-position:[X]% [Y]%;background-size:cover;"
If we change the state (such as
this.state.x
) to cause a re-render, the style format is changed to:style="background: url([URL]) [X']% [Y]% / cover rgb(255, 255, 255);"
Where this seems to break down is while changing the state of a URL inside of the
background
property while also defining abackgroundSize
.The initial render will return the expected style:
style="background:#ffffff url(http://i.imgur.com/aPd8qDo.png);background-size:cover;"
However, changing the URL results in rendering a style without
background-size
:style="background: url([URL]) rgb(255, 255, 255);"
Example Demo
The text was updated successfully, but these errors were encountered: