react icon indicating copy to clipboard operation
react copied to clipboard

marginBottom gets dropped sometimes

Open jussi-kalliokoski opened this issue 12 years ago • 6 comments

In the product I'm currently developing, there's a case where the marginBottom value gets dropped by React sometimes. Unfortunately I couldn't manage to reproduce the issue in my attempts at a reduced test case, and I can't post the link to the unreleased product yet, but I thought I'd report it anyway in case someone has additional information to go by.

Basically the case is that in the application, I have components whose style value I set to an object that is something like this:

var style = {
    margin: "0 10px",
    marginBottom: "6px",
};

These values are dependant on the screen size, which is listened to with window.onresize and then updated with something like setProps({ screen: { width: screen.width, height: screen.height } });.

However, what I noticed is that when resizing the screen, more often than not, the components end up not having a vertical margin at all. I know that this is caused by React because I tried logging the value assigned to style in render() and its sound, and actually the render() is not even called when you hit this behavior. Something that makes the problem go away is setting the style as

var style = {
    margin: "0 10px 6px 10px",
};

instead, which is what I'm doing for now. The application is running v0.10.0, but I just tried with v0.11.2 and it's still reproducible.

jussi-kalliokoski avatar Sep 23 '14 10:09 jussi-kalliokoski

Overlapping styles are not currently supported by React, see #2013. While it would be nice to support it, run-time performance is affected so it's a tricky subject (although offline transforms is definitely an idea).

syranide avatar Sep 23 '14 11:09 syranide

Ah, I see. Thanks, that makes sense. Closing.

jussi-kalliokoski avatar Sep 23 '14 12:09 jussi-kalliokoski

I actually think that it wouldn't be terrible to make this work. I'm betting that the reason it doesn't is that we expand shortcut properties and set each individual property (eg margin gets expanded into marginTop, marginRight, marginBottom, marginLeft) and we probably screw up key order (which is isn't technically guaranteed anyway). There would be some perf tradeoffs to make this work but technically shouldn't be too hard. Not sure if it's worth it. #2013 has some good points.

zpao avatar Sep 23 '14 17:09 zpao

Hi, here is a simple use case: When i set the style of a React Component which is including a shorthand property and a modifier for that property ex. {border: 'solid 1px black', borderBottom: 'none'} than set a new style without the modifier {border: 'solid 1px black'} the new style object wont apply properly. In this case the inline style remains:

border-top-style: solid;
border-right-style: solid;
border-left-style: solid;
border-top-width: 1px;
border-right-width: 1px;
border-left-width: 1px;
border-top-color: black;
border-right-color: black;
border-left-color: black;

codepen example

azazdeaz avatar Mar 25 '15 12:03 azazdeaz

@azazdeaz {border: 'solid 1px black', borderBottom: 'none'} is invalid, you may not set overlapping styles.

syranide avatar Mar 25 '15 12:03 syranide

Would be really nice to have overlapping styles working. I have an HOC footer I would like to pass elements to and place them according to my needs inside. I wrote the following code with react-bootstrap:

const Footer = React.createClass({
    render: function() {
        var children = React.Children.map(this.props.children, function(child){
            return React.cloneElement(child, { className :"btn btn-primary", margin : "40" });
        });
        return (
            <div style={style}>
                {children}
            </div>
        );
    }
});

And got className applied, while margin not. Would be convinient from my point to have both working.

polyakoff avatar Nov 09 '16 21:11 polyakoff