Skip to content

Commit 8ee024f

Browse files
authored
Reload the page only if the change is for the current page. (vercel#2589)
Sometimes, we've to reload the page for some changes. Even if so, we need to do it if that change is for the current page.
1 parent c97aca5 commit 8ee024f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

client/webpack-hot-middleware-client.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ export default () => {
3232

3333
const { err, Component } = Router.components[route] || {}
3434

35+
if (err) {
36+
// reload to recover from runtime errors
37+
Router.reload(route)
38+
}
39+
40+
if (Router.route !== route) {
41+
// If this is a not a change for a currently viewing page.
42+
// We don't need to worry about it.
43+
return
44+
}
45+
3546
if (!Component) {
3647
// This only happens when we create a new page without a default export.
3748
// If you removed a default export from a exising viewing page, this has no effect.
3849
console.log(`Hard reloading due to no default component in page: ${route}`)
3950
window.location.reload()
40-
return
41-
}
42-
43-
if (err) {
44-
// reload to recover from runtime errors
45-
Router.reload(route)
4651
}
4752
}
4853
}

0 commit comments

Comments
 (0)