]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix instance accessed via $parent chain when using expose() (...
authorAustin Keener <keeneraustin@yahoo.com>
Fri, 2 Jul 2021 11:51:54 +0000 (07:51 -0400)
committerGitHub <noreply@github.com>
Fri, 2 Jul 2021 11:51:54 +0000 (07:51 -0400)
packages/runtime-core/__tests__/apiExpose.spec.ts
packages/runtime-core/src/componentPublicInstance.ts

index fb957b68db3d0ed8dc26945ad638af7035e1117e..9f7ba535031bd917b568283032836f445eb57cae 100644 (file)
@@ -171,13 +171,20 @@ describe('api: expose', () => {
   })
 
   test('expose should allow access to built-in instance properties', () => {
+    const GrandChild = defineComponent({
+      render() {
+        return h('div')
+      }
+    })
+
+    const grandChildRef = ref()
     const Child = defineComponent({
       render() {
         return h('div')
       },
       setup(_, { expose }) {
         expose()
-        return {}
+        return () => h(GrandChild, { ref: grandChildRef })
       }
     })
 
@@ -190,5 +197,7 @@ describe('api: expose', () => {
     const root = nodeOps.createElement('div')
     render(h(Parent), root)
     expect(childRef.value.$el.tag).toBe('div')
+    expect(grandChildRef.value.$parent).toBe(childRef.value)
+    expect(grandChildRef.value.$parent.$parent).toBe(grandChildRef.value.$root)
   })
 })
index 9206b974ba4fd347d73eeea3d08c2e217cbaf5cd..7240120e5b7bc42fff86f9c8d07538a26ae00ddf 100644 (file)
@@ -1,6 +1,7 @@
 import {
   ComponentInternalInstance,
   Data,
+  getExposeProxy,
   isStatefulComponent
 } from './component'
 import { nextTick, queueJob } from './scheduler'
@@ -217,7 +218,7 @@ const getPublicInstance = (
   i: ComponentInternalInstance | null
 ): ComponentPublicInstance | ComponentInternalInstance['exposed'] | null => {
   if (!i) return null
-  if (isStatefulComponent(i)) return i.exposed ? i.exposed : i.proxy
+  if (isStatefulComponent(i)) return getExposeProxy(i) || i.proxy
   return getPublicInstance(i.parent)
 }