Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/e2e/app-dir/css-server-chunks/app/client/page.tsx
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>
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/css-server-chunks/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
Copy link
Contributor

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 like React.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:

import React from 'react'

export default function Root({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>{children}</body>
    </html>
  )
}

return (
<html>
<body>{children}</body>
</html>
)
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/css-server-chunks/app/server/page.tsx
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 test/e2e/app-dir/css-server-chunks/css-server-chunks.test.ts
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$/)])
)
})
})
3 changes: 3 additions & 0 deletions test/e2e/app-dir/css-server-chunks/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: blue;
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/css-server-chunks/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
5 changes: 5 additions & 0 deletions test/e2e/app-dir/css-server-chunks/pages/_app.js
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} />
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/css-server-chunks/pages/pages.js
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>
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/css-server-chunks/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: red;
}
Loading