mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27: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)
|
layout = layout(app.context)
|
||||||
}
|
}
|
||||||
this.setLayout(layout)
|
this.setLayout(layout)
|
||||||
|
|
||||||
<% if (isDev) { %>
|
<% if (isDev) { %>
|
||||||
// Hot reloading
|
// Hot reloading
|
||||||
setTimeout(() => hotReloadAPI(this), 100)
|
setTimeout(() => hotReloadAPI(this), 100)
|
||||||
@ -388,28 +387,23 @@ function nuxtReady (app) {
|
|||||||
|
|
||||||
<% if (isDev) { %>
|
<% if (isDev) { %>
|
||||||
// Special hot reload with asyncData(context)
|
// 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) {
|
function hotReloadAPI (_app) {
|
||||||
if (!module.hot) return
|
if (!module.hot) return
|
||||||
|
|
||||||
let $components = []
|
let $components = getNuxtChildComponents(_app.$nuxt, [])
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
$components.forEach(addHotReload.bind(_app))
|
$components.forEach(addHotReload.bind(_app))
|
||||||
}
|
}
|
||||||
@ -440,8 +434,9 @@ function addHotReload ($component, depth) {
|
|||||||
isHMR: true,
|
isHMR: true,
|
||||||
next: next.bind(this)
|
next: next.bind(this)
|
||||||
})
|
})
|
||||||
|
const context = app.context
|
||||||
<%= (loading ? 'this.$loading.start && this.$loading.start()' : '') %>
|
<%= (loading ? 'this.$loading.start && this.$loading.start()' : '') %>
|
||||||
callMiddleware.call(this, Components, app.context)
|
callMiddleware.call(this, Components, context)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// If layout changed
|
// If layout changed
|
||||||
if (depth !== 0) return Promise.resolve()
|
if (depth !== 0) return Promise.resolve()
|
||||||
|
@ -30,7 +30,6 @@ export default {
|
|||||||
parent = parent.$parent
|
parent = parent.$parent
|
||||||
}
|
}
|
||||||
data.nuxtChildDepth = depth
|
data.nuxtChildDepth = depth
|
||||||
|
|
||||||
const transition = transitions[depth] || defaultTransition
|
const transition = transitions[depth] || defaultTransition
|
||||||
let transitionProps = {}
|
let transitionProps = {}
|
||||||
transitionsKeys.forEach((key) => {
|
transitionsKeys.forEach((key) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user