Skip to content

Ternary sx statement with undefined causes component unmount/remount #2164

Open
@jonathanharrell

Description

@jonathanharrell

Describe the bug
Let's say I have a basic React component:

const Test = (props) => {
  return (
    <div {...props}>{props.children}</div>
  );
};

And then I use sx on that component, swapping between an object and undefined based on some state:

<Test sx={someBoolean ? myStyles : undefined}/>

This causes the Test component to unmount/remount (along with any children it renders).

This is because when the sx prop is defined, Test is rendered inside EmotionCssPropInternal and when it's undefined, it's rendered on its own.

I don't believe this is the case when using emotion's css prop.

Expected behavior
EmotionCssPropInternal should wrap any component that uses sx prop, even if that prop value is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions