-
Notifications
You must be signed in to change notification settings - Fork 9
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
Using next-yak converts server components to client components #112
Comments
hi @inuwan thanks for reporting the issue could you please set up a minimal reproduction example? |
it looks like there is a bug in next.js and or css-loader but I am still investigating it the error error definition: |
Created a reproduction example here: https://github.com/jantimon/reproduction-next-server-component-css-error |
Reported at next.js: vercel/next.js#67591 |
As a intermediate solution you could split the code - everything works as long as |
I think we should create another example with this case in our repo. What do you think @jantimon ? |
@Mad-Kat - yes we should definitely improve our examples (a more realistic one and a very basic one) 👍 Btw I found the reason for this bug. During processing Next.js identifies |
I tried this, it worked at first. But the navigating on the page triggered the error again... |
There is an open bug in next.js but I believe nobody is working on it can you please show us how you are splitting it? |
This bug is tricky but we have not forgotten about it 😄 How next-yak CSS Extraction WorksFirst, let's understand how next-yak normally processes styled components. When you write: const Button = styled.button`
background-color: #007bff;
color: #fff;
`; The next-yak SWC plugin transforms this into two parts:
This The Compilation Layer ChallengeThe issue emerges due to how Next.js App Router handles compilations. There are three parallel webpack compilations happening:
During development, Next.js moves CSS processing from the RSC layer to the browser layer for better developer experience (enabling features like hot reload and sourcemaps). This is where our bug surfaces:
This creates a paradox where:
The error message about Diagram of the Issueflowchart TB
source["page.tsx
(generateMetadata and styled-components)"]
subgraph "RSC Layer"
rsc_process["yak-swc processes page.tsx
and adds a CSS import with !=!"]
end
subgraph "Browser Layer"
css_file["page.tsx (as CSS)"]
css_loader["yak css-loader"]
swc_loader["swc-loader with yak-swc"]
error["❌ Conflict:
Server-only API detected
in browser context"]
end
source --> rsc_process
rsc_process --"The CSS import can only be
processed in the browser layer"--> css_file
css_file --> css_loader
css_loader --"uses swc to compile the tsx to css code"--> swc_loader
swc_loader --> error
style source stroke-width:2px
style error stroke-width:2px,stroke-dasharray: 5 5
|
blocked by vercel/next.js#74821 |
Using a next-yak styled component with a server component (page.tsx) that defines the Next.js special function generateMetadata. I get the following error:
You are attempting to export "generateMetadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https:// │ nextjs.org/docs/getting-started/react-essentials#the-use-client-directive
If I remove the next-yak styled component, the error is eliminated.
The text was updated successfully, but these errors were encountered: