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

Fix double-reload / redirect when changing pages (#4388)

When changing a page `/_app` can be seen as “updated”,  but the router shouldn’t reload it, because there is an ongoing/going to be ongoing update.
This commit is contained in:
Tim Neutkens 2018-05-16 00:36:24 +02:00 committed by GitHub
parent 3db3f4b42a
commit 535bab167b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,14 +179,26 @@ export default class HotReloader {
this.send('reload', route)
}
let changedPageRoutes = []
for (const [n, hash] of chunkHashes) {
if (!this.prevChunkHashes.has(n)) continue
if (this.prevChunkHashes.get(n) === hash) continue
const route = toRoute(relative(rootDir, n))
changedPageRoutes.push(route)
}
// This means `/_app` is most likely included in the list.
// We filter it out because `/_app` will be re-rendered with the page
if (changedPageRoutes.length > 1) {
changedPageRoutes = changedPageRoutes.filter((route) => route !== '/_app')
}
for (const changedPageRoute of changedPageRoutes) {
// notify change to recover from runtime errors
this.send('change', route)
this.send('change', changedPageRoute)
}
}
@ -277,6 +289,10 @@ export default class HotReloader {
}
async ensurePage (page) {
// Make sure we don't re-build or dispose prebuilt pages
if (page === '/_error' || page === '/_document' || page === '/_app') {
return
}
await this.onDemandEntries.ensurePage(page)
}
}