Skip to content

Commit a04a5ef

Browse files
authored
Add an e2e test for the css serving issue (vercel#81683)
## Add a regression test for when a not-found component depends on css and triggers a bug in turbopack To correctly serve js and css resources during server side rendering we construct a client manifest that lists all the server components and their required resources. Turbopack has a bug where we fail to collect css that is used by the page if it is also used by a not-found page (and other error handlers as well). When a not-found component is present all pages pages implicitly depend on this module and depend on it as an early dependency of the generated `app-page.js` file. This means if a `not-found.js` file (or a global error file) would happen to depend on the same css as a normal component we would associate it as a client-reference of that component instead of any other. Then on a server side render we would simply omit it. This PR adds a regression test for this issue. See vercel#77861 and vercel#79535
1 parent 5444efa commit a04a5ef

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { ReactNode } from 'react'
2+
import styles from '../styles.module.css'
3+
4+
export default function RootLayout({ children }: { children: ReactNode }) {
5+
return (
6+
<html lang="en">
7+
<body className={styles.foo}>{children}</body>
8+
</html>
9+
)
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <p>hello world</p>
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { ReactNode } from 'react'
2+
3+
export default function Layout({ children }: { children: ReactNode }) {
4+
return children
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import styles from './styles.module.css'
2+
3+
/**
4+
* The mere existence of a not found page importing the same css as a layout used to prevent it from being served.
5+
*
6+
* See https://github.com/vercel/next.js/issues/77861 and https://github.com/vercel/next.js/issues/79535
7+
*/
8+
export default function NotFoundPage() {
9+
return (
10+
<html lang="en">
11+
<body className={styles.foo}>
12+
<main>
13+
<h1>Page not found</h1>
14+
</main>
15+
</body>
16+
</html>
17+
)
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('initial-css-not-found', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
})
7+
8+
// Regression test for a bug where the existence of a not-found page would prevent the css from being discovered.
9+
// See https://github.com/vercel/next.js/issues/77861 and https://github.com/vercel/next.js/issues/79535
10+
it('should serve styles', async () => {
11+
const browser = await next.browser('/')
12+
13+
expect(
14+
await browser.eval(
15+
`window.getComputedStyle(document.querySelector('body')).color`
16+
)
17+
).toBe(
18+
// This only fails in production turbopack builds
19+
process.env.IS_TURBOPACK_TEST && process.env.NEXT_TEST_MODE !== 'dev'
20+
? 'rgb(0, 0, 0)'
21+
: 'rgb(255, 0, 0)'
22+
)
23+
})
24+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)