-
Notifications
You must be signed in to change notification settings - Fork 18
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
Macro system does not support calling a function which calls styled
#24
Comments
@ncknuna This should be fixed in release 1.1.3. The issue was that macaron tries to extract every call of styled functions, but it was unable to do so because of a variable reference that it couldn't resolve. In this case you want to opt out of macaron's extraction since you know you will only call it inside const Component = /* macaron-ignore */ styled("button", {}); /* macaron-ignore */ globalStyle(selector, styles) macaron will skip extracting these functions and will directly extract where you've called |
Another thing, you can't return a styled component from |
Thanks for the quick fix! I forked and modified the previous stackblitz and now it works: https://stackblitz.com/edit/macaron-css-macaron-tj3yss?file=src/App.tsx The main concern I have now is that it's a bit verbose, needing to be wrapped by both
Can you think of any way to make this a bit more elegant? Also happy to take this to a discussion now that the original issue was fixed, and close this one. |
I have a few ideas on how this can be made less verbose. Lets move this to a discussion |
Vanilla-extract also has a concept of function serialisers that it uses to serialise recipes etc, which allow them to be returned from |
Started disccusion here: #26 Closing this as completed |
[transferred to an issue from the vanilla extract discord]
Hello! I'm thinking of moving a codebase from emotionjs to macaron, but I've run into a sticking point: our component library often wraps a third-party component lib (ant design in this case) and we often need to restyle the underlying component lib in certain situations.
In emotion, we could select the classnames that the third-party library was exposing, so we could do something like this:
// styles for my current component
paddingLeft: 12,
// styles for the third party lib
'& .ant-table-thead': {
fontSize: 24
},
'& .ant-table-tbody': ...
// other styles
Since vanilla extract doesn't support complex selectors targeting elements other than the current one, the easiest way I could think of doing this with vanilla extract is something like this:
const wrapperCls = style({
paddingLeft: 12,
})
globalStyle(
${wrapperCls} > .ant-table-thead
, {fontSize: 24
})
globalStyle(
${wrapperCls} > .ant-table-tbody
, ...)// other calls to
globalStyle
Which, while technically maybe the same number of lines, feels more clunky and forces a separation that I think makes the intention of the code less clear. I thought about possibly writing a utility function that would take the object style and make those multiple globalStyle calls for me, but it seems to throw "Maximum call stack size exceeded" errors, because I think the macro system doesn't know how to resolve the variable references.
Here's a stackblitz link: https://stackblitz.com/edit/macaron-css-macaron-rjwpfg?file=src/App.tsx
I was able to get it to work with Vanilla Extract (without macaron) if that's helpful: https://stackblitz.com/edit/vitejs-vite-63vac7?file=src/components/button/button.css.ts . Macaron would offer a cleaner upgrade path for me and closer to the DX that I'm looking for though
@Mokshit06 replied:
oh so i see what's happening, macaron is trying to extract the styled function inside sampleFn but it depends on a variable reference that is declared inside it so it is unable to extract
we should move this to a github issue
The text was updated successfully, but these errors were encountered: