1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Fix dynamic import page navigation (#4842)

Fixes #3775
This commit is contained in:
Tim Neutkens 2018-07-26 12:38:45 +02:00 committed by GitHub
parent f4988e7fa3
commit 8e2c199ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 0 deletions

View file

@ -5,6 +5,7 @@
"@babel/preset-flow"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"

View file

@ -2,6 +2,12 @@ import initNext, * as next from './'
import initOnDemandEntries from './on-demand-entries-client'
import initWebpackHMR from './webpack-hot-middleware-client'
// Temporary workaround for the issue described here:
// https://github.com/zeit/next.js/issues/3775#issuecomment-407438123
// The runtimeChunk doesn't have dynamic import handling code when there hasn't been a dynamic import
// The runtimeChunk can't hot reload itself currently to correct it when adding pages using on-demand-entries
import('./noop')
const {
__NEXT_DATA__: {
assetPrefix

0
client/noop.js Normal file
View file

View file

@ -0,0 +1 @@
export default () => <p>Hello</p>

View file

@ -0,0 +1,7 @@
import dynamic from 'next/dynamic'
const Hello = dynamic(import('../../components/hello.js'))
export default () => <div className='dynamic-page'>
<Hello />
</div>

View file

@ -0,0 +1,5 @@
import Link from 'next/link'
export default () => <div>
<Link href='/nav/dynamic'><a id='to-dynamic'>To dynamic import</a></Link>
</div>

View file

@ -1,6 +1,7 @@
/* global jasmine, describe, beforeAll, afterAll, it, expect */
import { join, resolve } from 'path'
import { existsSync } from 'fs'
import webdriver from 'next-webdriver'
import {
renderViaHTTP,
findPort,
@ -57,4 +58,21 @@ describe('On Demand Entries', () => {
if (!existsSync(indexPagePath)) return
}
})
it('should navigate to pages with dynamic imports', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/nav')
const text = await browser
.elementByCss('#to-dynamic').click()
.waitForElementByCss('.dynamic-page')
.elementByCss('p').text()
expect(text).toBe('Hello')
} finally {
if (browser) {
browser.close()
}
}
})
})