Skip to content

Commit

Permalink
fix: disable hmr in dev move (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed Mar 28, 2020
1 parent 6ec9246 commit bf8818a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 63 deletions.
11 changes: 3 additions & 8 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export default async function getBaseWebpackConfig(
cache: true,
cpus: config.experimental.cpus,
distDir: distDir,
parallel: false,
parallel: true,
sourceMap: false,
workerThreads: config.experimental.workerThreads,
}
Expand Down Expand Up @@ -477,7 +477,6 @@ export default async function getBaseWebpackConfig(
? undefined
: !isServerless
? [
{ 'next/router': 'next/dist/client/router.js' },
(context, request, callback) => {
const notExternalModules = [
'next/app',
Expand Down Expand Up @@ -577,7 +576,6 @@ export default async function getBaseWebpackConfig(
webpack5Experiential
? [
'enhanced-resolve',
{ 'next/router': 'next/dist/client/router.js' },
]
: []
),
Expand Down Expand Up @@ -843,11 +841,8 @@ export default async function getBaseWebpackConfig(
})
)
}
devPlugins.push(
new webpack.HotModuleReplacementPlugin({
multiStep: true,
})
)
!webpack5Experiential &&
devPlugins.push(new webpack.HotModuleReplacementPlugin())
}

return devPlugins
Expand Down
61 changes: 6 additions & 55 deletions packages/next/server/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ADDED = Symbol('added')
const BUILDING = Symbol('building')
const BUILT = Symbol('built')

const IS_WEBPACK_5 = true
const webpack5Experiential = parseInt(require('webpack').version) === 5

// Based on https://github.com/webpack/webpack/blob/master/lib/DynamicEntryPlugin.js#L29-L37
function addEntry(
Expand Down Expand Up @@ -96,29 +96,9 @@ export default function onDemandEntryHandler(
let reloading = false
let stopped = false
let reloadCallbacks: EventEmitter | null = new EventEmitter()
let multiStepBuild = { promises: [] }

multiStepBuild.promises.push(
new Promise(resolve => {
multiStepBuild.additionalPass = resolve
})
)
multiStepBuild.promises.push(
new Promise(resolve => {
multiStepBuild.done = resolve
})
)

multiStepBuild.promises.push(
new Promise(resolve => {
multiStepBuild.lastDoneEvent = resolve
})
)

let callbackSet = []
let callCount = []
for (const compiler of compilers) {
IS_WEBPACK_5 &&
webpack5Experiential &&
new DynamicEntryPlugin(compiler.context, async () => {
const theEntries = await Promise.all(getAllEntries(entries, compiler))
const allEntries = theEntries
Expand All @@ -135,15 +115,14 @@ export default function onDemandEntryHandler(
return allEntries
}).apply(compiler)

IS_WEBPACK_5 &&
webpack5Experiential &&
compiler.hooks.make.intercept({
register(tap) {
const initialFn = tap.fn
const cb = (compilation, callback) => {
const res = initialFn(compilation, callback)
if (tap.name === 'DynamicEntryPlugin') {
invalidator.startBuilding()
callbackSet.push(res)
}
return res
}
Expand All @@ -152,24 +131,7 @@ export default function onDemandEntryHandler(
},
})

if (compiler.name === 'client') {
compiler.hooks.additionalPass.tap('NextJsOnDemandEntries', () => {
multiStepBuild.additionalPass()
clearTimeout(multiStepBuild.timeout)
})
}
compiler.hooks.afterDone.tap('NextJsOnDemandEntries', () => {
if (callbackSet.length) {
// additionalPass initiated.
multiStepBuild.promises[0].then(() => {
clearInterval(multiStepBuild.timeout)
multiStepBuild.timeout = setTimeout(() => {
multiStepBuild.done()
}, 600)
})
}
})
!IS_WEBPACK_5 &&
!webpack5Experiential &&
compiler.hooks.make.tapPromise(
'NextJsOnDemandEntries',
(compilation: webpack.compilation.Compilation) => {
Expand Down Expand Up @@ -261,13 +223,6 @@ export default function onDemandEntryHandler(
}

invalidator.doneBuilding()
clearTimeout(multiStepBuild.timeout)

Promise.all([multiStepBuild.promises[0], multiStepBuild.promises[1]]).then(
() => {
multiStepBuild.lastDoneEvent()
}
)

if (hardFailedPages.length > 0 && !reloading) {
console.log(
Expand Down Expand Up @@ -420,12 +375,7 @@ export default function onDemandEntryHandler(

function handleCallback(err: Error) {
if (err) return reject(err)
Promise.all(multiStepBuild.promises).then(() => {
Promise.all(callbackSet).then(() => {
callbackSet = []
resolve()
})
})
resolve()
}
})
},
Expand All @@ -449,6 +399,7 @@ export default function onDemandEntryHandler(
})
} else {
if (!/^\/_next\/webpack-hmr/.test(req.url!)) return next()

const { query } = parse(req.url!, true)
const page = query.page
if (!page) return next()
Expand Down

0 comments on commit bf8818a

Please sign in to comment.