-
Notifications
You must be signed in to change notification settings - Fork 325
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
Improve CSS support in server components #1843
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! 🥳
Dumb question, but how would one turn on this flag? What's the copypasta? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frandiox, amazing. I reviewed the code although I wanted to debug it and had some issues.
A couple of comments:
- Should we be adding tests for this?
- Would it make sense to add dev docs for this? e.g. in separate file or beginning of the plugin on the behavior in SSR, SCR, client side, dev vs prod.
It's like in the modified // vite.config.js
// ...
plugins: [hydrogen({experimental: {css: 'global'}})] Once some of our CSS Modules users test this in their projects we can enable it by default 👍
It's actually tested. I've enabled this code path in
I started writing docs but then thought that, since this is a very experimental feature, perhaps we could release it without docs first to make sure there are no breaking changes for CSS Module users (we can contact some of them directly to try this out). Then, once we are sure the Having a second thought, perhaps we should just remove the whole |
Todos:
|
…rting the same styles in both client and server components
Alright I think this is finished. Changes since the last review:
@rennyG could you please check the updated docs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gold standard, @frandiox! Some nitty suggestions for dev docs style.
Co-authored-by: Ren Chaturvedi <63201605+rennyG@users.noreply.github.com>
Co-authored-by: Ren Chaturvedi <63201605+rennyG@users.noreply.github.com>
@frandiox how experimental is this feature at this point? It works wonderfully for me locally, but it breaks CSS for production builds (with no relevant errors that I can find during the build process). Happy to supply any logs or extra info you may need. It made a very drastic improvement for page loads locally, so I'm more than happy to help. FWIW i'm using https://github.com/MathiasGilson/tailwind-styled-component along w Tailwind |
@diemonster It seems to be quite stable and there are other devs using this in production. |
@frandiox yes, that was the issue. Note to anyone else that stumbles on this: you will need to load any additional CSS files in |
Description
Closes #953
Closes #943 (if vanilla-extract-css/vanilla-extract#751 is merged)
In #932 and other PRs we added support to import CSS Modules in server components. That approach works fine but requires a lot of code transformations and only works for default exports (server components in named exports do not include styles).
This PR adds a new implementation that doesn't need to transform code. Instead, it collects emitted style files from Vite's module graph (in dev) and Rollup output info (in prod) and extracts them in a single CSS file. Considerations:
Pros:
import './styles.css'
), and the styles will be inlined in the DOM.vanilla-extract
plugin to make it work).Cons:
Additional context
This new feature is added behind an
experimental.css
flag so that we don't break existing project that use CSS Modules. Once we make sure some users start using this without issues, we can make this the default behavior (APIs are the same so it shouldn't be a breaking change).Before submitting the PR, please make sure you do the following:
fixes #123
)yarn changeset add
if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning