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

fix to not call hot.accept on sub-components (#294) (#351)

This commit is contained in:
Naoyuki Kanezawa 2016-12-06 18:24:42 +09:00 committed by Guillermo Rauch
parent 9990a5fc78
commit edfdc482e3
2 changed files with 22 additions and 17 deletions

View file

@ -6,23 +6,28 @@ module.exports = function (content, sourceMap) {
const route = getRoute(this) const route = getRoute(this)
this.callback(null, `${content} this.callback(null, `${content}
if (module.hot) { (function (Component, route) {
if (!module.hot) return
if (!__resourceQuery) return
var qs = require('querystring')
var params = qs.parse(__resourceQuery.slice(1))
if (params.entry == null) return
module.hot.accept() module.hot.accept()
Component.__route = route
var Component = module.exports.default || module.exports if (module.hot.status() === 'idle') return
Component.__route = ${JSON.stringify(route)}
if (module.hot.status() !== 'idle') {
var components = next.router.components var components = next.router.components
for (var r in components) { for (var r in components) {
if (!components.hasOwnProperty(r)) continue if (!components.hasOwnProperty(r)) continue
if (components[r].Component.__route === ${JSON.stringify(route)}) { if (components[r].Component.__route === route) {
next.router.update(r, Component) next.router.update(r, Component)
} }
} }
} })(module.exports.default || module.exports, ${JSON.stringify(route)})
}
`, sourceMap) `, sourceMap)
} }

View file

@ -18,7 +18,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
const entry = {} const entry = {}
const defaultEntries = hotReload ? ['next/dist/client/webpack-hot-middleware-client'] : [] const defaultEntries = hotReload ? ['next/dist/client/webpack-hot-middleware-client'] : []
for (const p of pages) { for (const p of pages) {
entry[join('bundles', p)] = defaultEntries.concat(['./' + p]) entry[join('bundles', p)] = defaultEntries.concat([`./${p}?entry`])
} }
const nextPagesDir = join(__dirname, '..', '..', 'pages') const nextPagesDir = join(__dirname, '..', '..', 'pages')
@ -26,7 +26,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
const errorEntry = join('bundles', 'pages', '_error.js') const errorEntry = join('bundles', 'pages', '_error.js')
const defaultErrorPath = join(nextPagesDir, '_error.js') const defaultErrorPath = join(nextPagesDir, '_error.js')
if (!entry[errorEntry]) { if (!entry[errorEntry]) {
entry[errorEntry] = defaultEntries.concat([defaultErrorPath]) entry[errorEntry] = defaultEntries.concat([defaultErrorPath + '?entry'])
} }
const errorDebugEntry = join('bundles', 'pages', '_error-debug.js') const errorDebugEntry = join('bundles', 'pages', '_error-debug.js')
@ -78,14 +78,14 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
.replace(/[\\/]package\.json$/, '') .replace(/[\\/]package\.json$/, '')
const loaders = (hotReload ? [{ const loaders = (hotReload ? [{
test: /\.js$/, test: /\.js(\?[^?]*)?$/,
loader: 'hot-self-accept-loader', loader: 'hot-self-accept-loader',
include: [ include: [
join(dir, 'pages'), join(dir, 'pages'),
nextPagesDir nextPagesDir
] ]
}, { }, {
test: /\.js$/, test: /\.js(\?[^?]*)?$/,
loader: 'react-hot-loader/webpack', loader: 'react-hot-loader/webpack',
exclude: /node_modules/ exclude: /node_modules/
}] : []) }] : [])
@ -93,7 +93,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
test: /\.json$/, test: /\.json$/,
loader: 'json-loader' loader: 'json-loader'
}, { }, {
test: /\.(js|json)$/, test: /\.(js|json)(\?[^?]*)?$/,
loader: 'emit-file-loader', loader: 'emit-file-loader',
include: [dir, nextPagesDir], include: [dir, nextPagesDir],
exclude (str) { exclude (str) {
@ -119,7 +119,7 @@ export default async function createCompiler (dir, { hotReload = false, dev = fa
] ]
} }
}, { }, {
test: /\.js$/, test: /\.js(\?[^?]*)?$/,
loader: 'babel', loader: 'babel',
include: [dir, nextPagesDir], include: [dir, nextPagesDir],
exclude (str) { exclude (str) {