Skip to content

Commit

Permalink
Add missing key prop for array elements in _document (#8132)
Browse files Browse the repository at this point in the history
* Add missing keys for array elements

* Add test for missing key prop in app-document
  • Loading branch information
ijjk authored and timneutkens committed Jul 27, 2019
1 parent f5edfeb commit 13fa282
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ export class NextScript extends Component<OriginProps> {
<script
async
id={`__NEXT_PAGE__${page}`}
key={page}
src={
assetPrefix +
(dynamicBuildId
Expand All @@ -623,6 +624,7 @@ export class NextScript extends Component<OriginProps> {
<script
async
id={`__NEXT_PAGE__${page}`}
key={`${page}-modern`}
src={
assetPrefix +
getOptionalModernScriptVariant(
Expand Down Expand Up @@ -650,6 +652,7 @@ export class NextScript extends Component<OriginProps> {
: `/_next/static/${buildId}/pages/_app.js`) +
_devOnlyInvalidateCacheQueryString
}
key="_app"
nonce={this.props.nonce}
crossOrigin={this.props.crossOrigin || process.crossOrigin}
{...(process.env.__NEXT_MODERN_BUILD ? { noModule: true } : {})}
Expand All @@ -665,6 +668,7 @@ export class NextScript extends Component<OriginProps> {
: `/_next/static/${buildId}/pages/_app.module.js`) +
_devOnlyInvalidateCacheQueryString
}
key="_app-modern"
nonce={this.props.nonce}
crossOrigin={this.props.crossOrigin || process.crossOrigin}
type="module"
Expand Down
20 changes: 18 additions & 2 deletions test/integration/app-document/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,35 @@ import rendering from './rendering'
import client from './client'
import csp from './csp'

const context = {}
const context = {
output: ''
}
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5

const collectOutput = message => {
context.output += message
}

describe('Document and App', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(join(__dirname, '../'), context.appPort)
context.server = await launchApp(join(__dirname, '../'), context.appPort, {
onStdout: collectOutput,
onStderr: collectOutput
})

// pre-build all pages at the start
await Promise.all([renderViaHTTP(context.appPort, '/')])
})
afterAll(() => killApp(context.server))

it('should not have any missing key warnings', async () => {
await renderViaHTTP(context.appPort, '/')
expect(context.output).not.toMatch(
/Each child in a list should have a unique "key" prop/
)
})

rendering(
context,
'Rendering via HTTP',
Expand Down
13 changes: 10 additions & 3 deletions test/lib/next-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,18 @@ export function runNextCommandDev (argv, stdOut, opts = {}) {
if (/ready on/i.test(message)) {
resolve(stdOut ? message : instance)
}
if (typeof opts.onStdout === 'function') {
opts.onStdout(message)
}
process.stdout.write(message)
}

function handleStderr (data) {
process.stderr.write(data.toString())
const message = data.toString()
if (typeof opts.onStderr === 'function') {
opts.onStderr(message)
}
process.stderr.write(message)
}

instance.stdout.on('data', handleStdout)
Expand All @@ -160,8 +167,8 @@ export function runNextCommandDev (argv, stdOut, opts = {}) {
}

// Launch the app in dev mode.
export function launchApp (dir, port) {
return runNextCommandDev([dir, '-p', port])
export function launchApp (dir, port, opts) {
return runNextCommandDev([dir, '-p', port], undefined, opts)
}

export function nextBuild (dir, args = [], opts = {}) {
Expand Down

0 comments on commit 13fa282

Please sign in to comment.