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

Always transform styled-jsx for rsc and error with client-only condition #43386

Merged
merged 2 commits into from Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/next/build/swc/options.js
Expand Up @@ -117,14 +117,13 @@ function getBaseSWCOptions({
: nextConfig?.compiler?.reactRemoveProperties,
modularizeImports: nextConfig?.experimental?.modularizeImports,
relay: nextConfig?.compiler?.relay,
// Disable css-in-js transform on server layer for server components
...(isServerLayer
? {}
: {
emotion: getEmotionOptions(nextConfig, development),
styledComponents: getStyledComponentsOptions(nextConfig, development),
styledJsx: true,
}),
// Always transform styled-jsx and error when `client-only` condition is triggered
styledJsx: true,
// Disable css-in-js libs (without client-only integration) transform on server layer for server components
...(!isServerLayer && {
emotion: getEmotionOptions(nextConfig, development),
styledComponents: getStyledComponentsOptions(nextConfig, development),
}),
serverComponents: hasServerComponents
? {
isServer: !!isServerLayer,
Expand Down
8 changes: 0 additions & 8 deletions test/e2e/app-dir/rsc-errors.test.ts
Expand Up @@ -90,14 +90,6 @@ describe('app dir - rsc errors', () => {
)
})

it('should not transform css-in-js such as styled-jsx in server components', async () => {
const html = await renderViaHTTP(next.url, '/not-transform/styled-jsx')

expect(html).toMatch(
/<style>\s*\.this-wont-be-transformed\s*\{\s*color:\s*purple;\s*\}\s*<\/style>/
)
})

it('should error when page component export is not valid', async () => {
const html = await renderViaHTTP(
next.url,
Expand Down

This file was deleted.

@@ -1,5 +1,11 @@
import JSXStyle from 'styled-jsx/style'

export default function Page() {
return <JSXStyle>{`p{color:red}`}</JSXStyle>
return (
<div>
<style jsx>{`
p {
color: red;
}
`}</style>
</div>
)
}