-
Notifications
You must be signed in to change notification settings - Fork 29.2k
Test that there are no server-side CSS chunks #82471
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
Merged
+90
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client' | ||
|
||
import '../../global.css' | ||
import styles from '../../styles.module.css' | ||
|
||
export default function Page() { | ||
return <div className={styles.foo}>Hello</div> | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import '../../global.css' | ||
import styles from '../../styles.module.css' | ||
|
||
export default function Page() { | ||
return <div className={styles.foo}>Hello</div> | ||
} |
47 changes: 47 additions & 0 deletions
47
test/e2e/app-dir/css-server-chunks/css-server-chunks.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
|
||
describe('css-server-chunks', () => { | ||
const { next, skipped } = nextTestSetup({ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}) | ||
|
||
if (skipped) { | ||
return | ||
} | ||
|
||
it('should not write CSS chunks for the server', async () => { | ||
// Fetch all routes to compile them in development | ||
expect((await next.fetch('/client')).status).toBe(200) | ||
expect((await next.fetch('/server')).status).toBe(200) | ||
expect((await next.fetch('/pages')).status).toBe(200) | ||
|
||
let clientChunks = ( | ||
await fs.readdir(path.join(next.testDir, '.next', 'static'), { | ||
recursive: true, | ||
}) | ||
).filter((f) => f.endsWith('.js') || f.endsWith('.css')) | ||
expect(clientChunks).toEqual( | ||
expect.arrayContaining([expect.stringMatching(/\.css$/)]) | ||
) | ||
|
||
let serverChunks = ( | ||
await Promise.all( | ||
['.next/server/app', '.next/server/pages'].map((d) => | ||
fs.readdir(path.join(next.testDir, d), { | ||
recursive: true, | ||
encoding: 'utf8', | ||
}) | ||
) | ||
) | ||
) | ||
.flat() | ||
.filter((f) => f.endsWith('.js') || f.endsWith('.css')) | ||
expect(serverChunks).not.toBeEmpty() | ||
expect(serverChunks).not.toEqual( | ||
expect.arrayContaining([expect.stringMatching(/\.css$/)]) | ||
) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
color: blue; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../global.css' | ||
|
||
export default function App({ Component, pageProps }) { | ||
return <Component {...pageProps} /> | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import styles from '../styles.module.css' | ||
|
||
export default function Page() { | ||
return <div className={styles.foo}>Hello</div> | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.foo { | ||
color: red; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing React import for TypeScript type usage. The file uses
React.ReactNode
without importing React, which will cause a TypeScript compilation error.View Details
Analysis
The layout component uses the TypeScript type
React.ReactNode
in the props definition but doesn't import React. While Next.js 13+ automatically imports React for JSX usage, TypeScript types likeReact.ReactNode
still require an explicit import statement. This will cause the TypeScript compiler to fail with an error like "Cannot find name 'React'" when building or type-checking the project.The test setup expects this file to compile successfully as part of the e2e test, but it will fail during the TypeScript compilation phase, preventing the test from running.
Recommendation
Add the React import at the top of the file: