Unverified Commit a04a5efe authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Add an e2e test for the css serving issue (#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  #77861 and  #79535
parent 5444efa2
import type { ReactNode } from 'react'
import styles from '../styles.module.css'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body className={styles.foo}>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
import type { ReactNode } from 'react'
export default function Layout({ children }: { children: ReactNode }) {
return children
}
import styles from './styles.module.css'
/**
* The mere existence of a not found page importing the same css as a layout used to prevent it from being served.
*
* See https://github.com/vercel/next.js/issues/77861 and https://github.com/vercel/next.js/issues/79535
*/
export default function NotFoundPage() {
return (
<html lang="en">
<body className={styles.foo}>
<main>
<h1>Page not found</h1>
</main>
</body>
</html>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('initial-css-not-found', () => {
const { next } = nextTestSetup({
files: __dirname,
})
// Regression test for a bug where the existence of a not-found page would prevent the css from being discovered.
// See https://github.com/vercel/next.js/issues/77861 and https://github.com/vercel/next.js/issues/79535
it('should serve styles', async () => {
const browser = await next.browser('/')
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('body')).color`
)
).toBe(
// This only fails in production turbopack builds
process.env.IS_TURBOPACK_TEST && process.env.NEXT_TEST_MODE !== 'dev'
? 'rgb(0, 0, 0)'
: 'rgb(255, 0, 0)'
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment