Output static class names #3082
-
What's the reason for outputting the original function call and all nested CSS declarations for Given a React component like below: const Container = styled('div', {
base: {
bg: 'red',
height: 100,
width: 100
}
})
const App = () => (
<Container>
<div className={css({ fontSize: "2xl", fontWeight: 'bold' })}>
Hello 🐼!
</div>
</Container>
) I would expect the output JS to be something equivalent to: const App = () => jsx('div', {
className: 'height-100 width-100 bg-red',
children: jsx('div', {
className: 'fontSize-2xl fontWeight-bold',
children: 'Hello 🐼!'
})
}) But instead it seems like it still calculates the class names at runtime (minified code below but you can see the const bf = Kf(),
Zf = bf('div', { base: { height: 100, width: 100, bg: 'red' } })
function Jf() {
return Nl.jsx(Zf, {
children: Nl.jsx('div', {
className: Sr({ fontSize: '2xl', fontWeight: 'bold' }),
children: 'Hello 🐼!'
})
})
} I assumed that all the relevant information would be available to Panda to be able to remove this runtime step and just output static class names with the element? Especially as we're not doing anything dynamic here. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I guess the easy fix is to put the So like: const styles = css({ fontSize: "2xl", fontWeight: 'bold' });
const App = () => (
<Container>
<div className={styles}>
Hello 🐼!
</div>
</Container>
) That's what I'm doing for the component library I'm building. |
Beta Was this translation helpful? Give feedback.
-
making a bundler plugins with source code transformations is a whole different beast than "just" using static analysis and generating a CSS sheet based on that it means you have:
fwiw it's exactly what I started exploring a while ago here, but I don't want to have to maintain this on my own, contributions are welcome and the foundations are here |
Beta Was this translation helpful? Give feedback.
making a bundler plugins with source code transformations is a whole different beast than "just" using static analysis and generating a CSS sheet based on that
it means you have:
xxx
is not statically extractable incss(xxx)
? etc)fwiw it's exactly what I started exploring a while ago here, but I don't want to have to maintain this on my own, contributions are welcome and the foundations are here