mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix: Fix Hot reloading
This commit is contained in:
parent
70cfc7fcc9
commit
3b9f293e40
@ -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()
|
||||
|
@ -30,7 +30,6 @@ export default {
|
||||
parent = parent.$parent
|
||||
}
|
||||
data.nuxtChildDepth = depth
|
||||
|
||||
const transition = transitions[depth] || defaultTransition
|
||||
let transitionProps = {}
|
||||
transitionsKeys.forEach((key) => {
|
||||
|
Loading…
Reference in New Issue
Block a user