Skip to content
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

🐛 Object passed to style prop gets mutated, which can lead to inconsistencies #1211

Open
tjosepo opened this issue Apr 18, 2023 · 0 comments
Labels

Comments

@tjosepo
Copy link
Member

tjosepo commented Apr 18, 2023

Describe the bug

Because Orbit styleprops don't support all CSS properties, we sometimes have to pass an object to the styles property.

<Div styles={{ transition: "all 0.3s linear" }} />

It might be desireable to store the style object in a variable, to be able to reuse the styles across components:

const styles = { transition: "all 0.3s linear" }

return (
  <>
    <Div styles={styles} />
    <Div styles={styles} />
  </>
);

However, doing so might lead to hard-to-understand bugs, as the object that is passed to the style prop seems to be directly mutated by Orbit, which makes sharing the object potentially dangerous:

const styles = { transition: "all 0.3s linear" }

return (
  <>
    <Div backgroundColor="red" styles={styles} />
    <Div styles={styles} /> // ⚠️ This will have a red background color!!
  </>
);

Steps to reproduce

See above.

Expected results

Orbit should not mutate objects passed as props directly, as those might be shared between components.

Reproducible demo

https://codesandbox.io/embed/orbit-transition-style-bug-g6u27z?fontsize=14&hidenavigation=1&module=%2FApp.tsx&theme=dark

@tjosepo tjosepo added the bug label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant