Skip to content

Commit

Permalink
fix: reload page after new live deploy (Loading chunk failed error).
Browse files Browse the repository at this point in the history
  • Loading branch information
rinu committed Mar 12, 2021
1 parent f08f4ef commit 2b94b54
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/vue-app/template/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,19 @@ export function resolveRouteComponents (route, fn) {
flatMapComponents(route, async (Component, instance, match, key) => {
// If component is a function, resolve it
if (typeof Component === 'function' && !Component.options) {
Component = await Component()
try {
Component = await Component()
} catch (error) {
// Handle chunk loading errors
// This may be due to a new deployment or a network problem
if (error && error.name === 'ChunkLoadError' && window.location.hash !== '#retry') {
// mark the page not to reload infinitely
window.location.hash = '#retry'
window.location.reload(true /* skip cache */)
}

throw error
}
}
match.components[key] = Component = sanitizeComponent(Component)
return typeof fn === 'function' ? fn(Component, instance, match, key) : Component
Expand Down

0 comments on commit 2b94b54

Please sign in to comment.