Skip to content

CSS backgroundSize property lost when re-rendering an image URL inside of an adjacent background property #5030

@ggdouglas

Description

@ggdouglas

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:

var style = {
    background: `#ffffff url(${this.state.url})`,
    backgroundPosition: `${this.state.x}% ${this.state.y}%`,
    backgroundSize: 'cover'
};

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 a backgroundSize.

var style = {
    background: `#ffffff url(${url})`,
    backgroundSize: 'cover'
};

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions