Ver Fonte

fix: account for nested render calls

close #13131
Evan You há 2 anos atrás
pai
commit
db9c566032
1 ficheiros alterados com 5 adições e 6 exclusões
  1. 5 6
      src/core/instance/render.ts

+ 5 - 6
src/core/instance/render.ts

@@ -15,7 +15,7 @@ import VNode, { createEmptyVNode } from '../vdom/vnode'
 
 import { isUpdatingChildComponent } from './lifecycle'
 import type { Component } from 'types/component'
-import { setCurrentInstance } from 'v3/currentInstance'
+import { currentInstance, setCurrentInstance } from 'v3/currentInstance'
 import { syncSetupSlots } from 'v3/apiSetup'
 
 export function initRender(vm: Component) {
@@ -120,11 +120,10 @@ export function renderMixin(Vue: typeof Component) {
     // to the data on the placeholder node.
     vm.$vnode = _parentVnode!
     // render self
+    const prevInst = currentInstance
+    const prevRenderInst = currentRenderingInstance
     let vnode
     try {
-      // There's no need to maintain a stack because all render fns are called
-      // separately from one another. Nested component's render fns are called
-      // when parent component is patched.
       setCurrentInstance(vm)
       currentRenderingInstance = vm
       vnode = render.call(vm._renderProxy, vm.$createElement)
@@ -148,8 +147,8 @@ export function renderMixin(Vue: typeof Component) {
         vnode = vm._vnode
       }
     } finally {
-      currentRenderingInstance = null
-      setCurrentInstance()
+      currentRenderingInstance = prevRenderInst
+      setCurrentInstance(prevInst)
     }
     // if the returned array contains only a single node, allow it
     if (isArray(vnode) && vnode.length === 1) {