-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix non-concurrent function _document (#31628)
This ensures functional `_document` is rendered correctly when not using concurrent mode. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Fixes: #31593 x-ref: #30156
- Loading branch information
Showing
11 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Head from 'next/head' | ||
|
||
export function Meta(props) { | ||
return ( | ||
<> | ||
<Head> | ||
<meta name="test-head-3" content="hello" /> | ||
<meta name="test-head-4" content="hello" /> | ||
</Head> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Html, Head, Main, NextScript } from 'next/document' | ||
|
||
export default function MyDocument() { | ||
return ( | ||
<Html> | ||
<Head /> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Head from 'next/head' | ||
import { Meta } from '../components/meta' | ||
|
||
export default function Page(props) { | ||
return ( | ||
<> | ||
<Head> | ||
<meta name="test-head-1" content="hello" /> | ||
<meta name="test-head-2" content="hello" /> | ||
</Head> | ||
<Meta /> | ||
<p>index page</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { renderViaHTTP } from 'next-test-utils' | ||
import cheerio from 'cheerio' | ||
import webdriver from 'next-webdriver' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { join } from 'path' | ||
|
||
describe('should set-up next', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'app/pages')), | ||
components: new FileRef(join(__dirname, 'app/components')), | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should have correct head tags in initial document', async () => { | ||
const html = await renderViaHTTP(next.url, '/') | ||
const $ = cheerio.load(html) | ||
|
||
for (let i = 1; i < 5; i++) { | ||
expect($(`meta[name="test-head-${i}"]`).attr()['content']).toBe('hello') | ||
} | ||
}) | ||
|
||
it('should have correct head tags after hydration', async () => { | ||
const browser = await webdriver(next.url, '/') | ||
|
||
for (let i = 1; i < 5; i++) { | ||
expect( | ||
await browser | ||
.elementByCss(`meta[name="test-head-${i}"]`) | ||
.getAttribute('content') | ||
).toBe('hello') | ||
} | ||
}) | ||
}) |
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
test/integration/document-functional-render-prop/app/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
experimental: { | ||
reactRoot: true, | ||
concurrentFeatures: true, | ||
}, | ||
webpack(config) { | ||
const { alias } = config.resolve | ||
// FIXME: resolving react/jsx-runtime https://github.com/facebook/react/issues/20235 | ||
alias['react/jsx-dev-runtime'] = 'react/jsx-dev-runtime.js' | ||
alias['react/jsx-runtime'] = 'react/jsx-runtime.js' | ||
|
||
// Use react 18 | ||
alias['react'] = 'react-18' | ||
alias['react-dom'] = 'react-dom-18' | ||
alias['react-dom/server'] = 'react-dom-18/server' | ||
|
||
return config | ||
}, | ||
} |
12 changes: 12 additions & 0 deletions
12
test/integration/document-functional-render-prop/app/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"scripts": { | ||
"next": "node -r ../test/require-hook.js ../../../../packages/next/dist/bin/next", | ||
"dev": "yarn next dev", | ||
"build": "yarn next build", | ||
"start": "yarn next start" | ||
}, | ||
"dependencies": { | ||
"react": "*", | ||
"react-dom": "*" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters