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

Doesn't work with global #6

Open
klm127 opened this issue Mar 26, 2024 · 0 comments
Open

Doesn't work with global #6

klm127 opened this issue Mar 26, 2024 · 0 comments

Comments

@klm127
Copy link

klm127 commented Mar 26, 2024

Say I style a component

const MyButton = ()=> {
  return <button class="common-button">
     Hello
     <style jsx global>{`
        .common-button {
          background-color: slateblue;
        }
      `}</style>
    </button>
}

And I use it

<div>
  <MyButton />
  <MyButton />
</div>

I would expect that the shared style would be extrapolated into a single <style> element on the dom, but instead it is repeated over and over again inside of every button

<button class="common-button">Hello<style>.common-button{ background-color=slateblue; }</style></button>
<button class="common-button">Hello<style>.common-button{ background-color=slateblue; }</style></button>

I think the solution is to use a css outside of the component, but there doesn't seem to be a way to do that with solid-styled-jsx.

Eg, for regular styled-jsx you would go:

import css from `styled-jsx/css`
const MyButton = ()=> {
  return <button class="common-button">
     Hello
     <style jsx>{butstyle}</style>
    </button>
}
const butstyle = css`
        .common-button {
          background-color: slateblue;
        }
`      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant