diff --git a/lib/app/client.js b/lib/app/client.js index 5cc56ad020..4c25e93c8f 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -362,7 +362,6 @@ function fixPrepatch (to, ___) { layout = layout(app.context) } this.setLayout(layout) - <% if (isDev) { %> // Hot reloading setTimeout(() => hotReloadAPI(this), 100) @@ -388,28 +387,23 @@ function nuxtReady (app) { <% if (isDev) { %> // Special hot reload with asyncData(context) +function getNuxtChildComponents($parent, $components = []) { + $parent.$children.forEach(($child) => { + if ($child.$vnode.data.nuxtChild && !$components.find(c =>(component.$options.__file === $child.$options.__file))) { + $components.push($child) + } + if ($child.$children && $child.$children.length) { + getNuxtChildComponents($child, $components) + } + }) + + return $components +} + function hotReloadAPI (_app) { if (!module.hot) return - let $components = [] - let $nuxt = _app.$nuxt - - while ($nuxt && $nuxt.$children && $nuxt.$children.length) { - $nuxt.$children.forEach((child, i) => { - if (child.$vnode.data.nuxtChild) { - let hasAlready = false - $components.forEach(component => { - if (component.$options.__file === child.$options.__file) { - hasAlready = true - } - }) - if (!hasAlready) { - $components.push(child) - } - } - $nuxt = child - }) - } + let $components = getNuxtChildComponents(_app.$nuxt, []) $components.forEach(addHotReload.bind(_app)) } @@ -440,8 +434,9 @@ function addHotReload ($component, depth) { isHMR: true, next: next.bind(this) }) + const context = app.context <%= (loading ? 'this.$loading.start && this.$loading.start()' : '') %> - callMiddleware.call(this, Components, app.context) + callMiddleware.call(this, Components, context) .then(() => { // If layout changed if (depth !== 0) return Promise.resolve() diff --git a/lib/app/components/nuxt-child.js b/lib/app/components/nuxt-child.js index 8d89530719..9fc6f6a8ed 100644 --- a/lib/app/components/nuxt-child.js +++ b/lib/app/components/nuxt-child.js @@ -30,7 +30,6 @@ export default { parent = parent.$parent } data.nuxtChildDepth = depth - const transition = transitions[depth] || defaultTransition let transitionProps = {} transitionsKeys.forEach((key) => {