Просмотр исходного кода

fix(runtime-vapor): ensure vapor slot unmounting removes vnode slot content (#14520)

edison 1 месяц назад
Родитель
Сommit
eff4cabc82

+ 28 - 0
packages/runtime-vapor/__tests__/vdomInterop.spec.ts

@@ -1504,6 +1504,34 @@ describe('vdomInterop', () => {
       await nextTick()
       expect(html()).toBe('slot text<!--if-->')
     })
+
+    test('unmounting vapor slot should remove vnode slot content', async () => {
+      const show = ref(true)
+
+      const VaporSlotOutlet = defineVaporComponent({
+        setup() {
+          return createSlot('default')
+        },
+      })
+
+      const { html } = define({
+        setup() {
+          return () =>
+            h('div', null, [
+              show.value
+                ? h(VaporSlotOutlet as any, null, {
+                    default: () => [h('span', 'slot vnode')],
+                  })
+                : null,
+            ])
+        },
+      }).render()
+
+      expect(html()).toBe('<div><span>slot vnode</span></div>')
+      show.value = false
+      await nextTick()
+      expect(html()).toBe('<div><!----></div>')
+    })
   })
 
   describe('Teleport', () => {

+ 1 - 1
packages/runtime-vapor/src/vdomInterop.ts

@@ -791,7 +791,7 @@ function renderVDOMSlot(
       if (currentBlock) {
         remove(currentBlock, parentNode)
       } else if (currentVNode) {
-        internals.um(currentVNode, parentComponent as any, null)
+        internals.um(currentVNode, parentComponent as any, null, true)
       }
     }