Skip to content

Commit

Permalink
Fix next/head in _app in RSC pages (#37928)
Browse files Browse the repository at this point in the history
* fix next/head in _app with rsc

* revert change

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
shuding and kodiakhq[bot] committed Jun 22, 2022
1 parent 1a0346e commit b04cdc9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit b04cdc9

Please sign in to comment.