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

Fix next/head in _app in RSC pages #37928

Merged
merged 3 commits into from
Jun 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,11 @@ export default async function getBaseWebpackConfig(
loader: 'next-flight-client-loader',
},
},
// _app should be treated as a client component as well as all its dependencies.
{
test: new RegExp(`_app\\.(${rawPageExtensions.join('|')})$`),
layer: 'sc_client',
},
]
: []
: []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function (context) {
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
})

it('should include global styles with `serverComponents: true`', async () => {
const browser = await webdriver(context.appPort, '/global-styles-rsc')
const currentColor = await browser.eval(
Expand All @@ -24,4 +25,10 @@ export default function (context) {
)
expect(currentColor).toMatchInlineSnapshot(`"rgb(255, 0, 0)"`)
})

it('should support next/head inside _app with RSC', async () => {
const browser = await webdriver(context.appPort, '/multi')
const title = await browser.eval(`document.title`)
expect(title).toBe('hi')
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ import streaming from './streaming'
import basic from './basic'
import { getNodeBuiltinModuleNotSupportedInEdgeRuntimeMessage } from 'next/dist/build/utils'

const appWithGlobalCss = `
const appWithGlobalCssAndHead = `
import '../styles.css'
import Head from 'next/head'

function App({ Component, pageProps }) {
return <Component {...pageProps} />
return <>
<Head>
<title>hi</title>
</Head>
<Component {...pageProps} />
</>
}

export default App
Expand Down Expand Up @@ -156,7 +162,7 @@ const nodejsRuntimeBasicSuite = {

const cssSuite = {
runTests: css,
beforeAll: () => appPage.write(appWithGlobalCss),
beforeAll: () => appPage.write(appWithGlobalCssAndHead),
afterAll: () => appPage.delete(),
}

Expand Down