Skip to content

Commit

Permalink
Fix dynamic import page navigation (#4842)
Browse files Browse the repository at this point in the history
Fixes #3775
  • Loading branch information
timneutkens authored Jul 26, 2018
1 parent f4988e7 commit 8e2c199
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions client/next-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added client/noop.js
Empty file.
1 change: 1 addition & 0 deletions test/integration/ondemand/components/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <p>Hello</p>
7 changes: 7 additions & 0 deletions test/integration/ondemand/pages/nav/dynamic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dynamic from 'next/dynamic'

const Hello = dynamic(import('../../components/hello.js'))

export default () => <div className='dynamic-page'>
<Hello />
</div>
5 changes: 5 additions & 0 deletions test/integration/ondemand/pages/nav/index.js
Original file line number Diff line number Diff line change
@@ -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>
18 changes: 18 additions & 0 deletions test/integration/ondemand/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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()
}
}
})
})

0 comments on commit 8e2c199

Please sign in to comment.