Skip to content

Shorthand CSS properties can cause style inconsistencies #8689

Closed
@bvaughn

Description

@bvaughn

I'm reporting a bug.

What is the current behavior?

  1. Render a host component with a style that contains both a shorthand CSS property and an over-writing longer form of the property (eg overflow and a conflicting overflowX and/or overflowY property).
  2. Update the host component (re-render) with the same shorthand property (eg overflow) but remove the longer form property (eg overflowX).
  3. The host component style is now invalid.

Examples

This bug can be reproduced here: https://plnkr.co/edit/7O1xZUqbD13ST2BAxcm9?p=preview

Update: I have since updated the Plnkr to use border instead of overflow since it makes the problem more immediately obvious to spot.

Example

  1. Render style={{ overflow: 'hidden', overflowY: 'auto' }}
  2. Render style={{ overflow: 'hidden' }}
  3. Expected: <div style="overflow: hidden;" />
  4. Actual: <div style="overflow-x: hidden;" />

Alternate example

  1. Render style={{ overflow: 'auto', overflowX: 'hidden', overflowY: 'hidden' }}
  2. Render style={{ overflow: 'auto' }}
  3. Expected: <div style="overflow: auto" />
  4. Actual: <div style="" />

You can also reproduce this bug with properties like margin, padding, border, etc.

Caveats

Note that if the shorthand value changes between renders things work as expected (because React explicitly updates the shorthand style).

I know this is very edge-case behavior and so may not be worth fixing. I originally noticed it by way of issue bvaughn/react-virtualized/issues/525.

Which versions of React / browser / OS are affected

This bug reproduces in Chrome, Firefox, and Safari using React 15.4.1 as well as the unreleased ReactDOMFiber renderer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions