|
|
@@ -20,6 +20,7 @@ import {
|
|
|
type Ref,
|
|
|
nextTick,
|
|
|
onScopeDispose,
|
|
|
+ onUnmounted,
|
|
|
reactive,
|
|
|
readonly,
|
|
|
ref,
|
|
|
@@ -1730,6 +1731,34 @@ describe('createFor', () => {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
+ test('component blocks are unmounted when clearing with fast remove', async () => {
|
|
|
+ const items = ref([1, 2])
|
|
|
+ const unmounted = vi.fn()
|
|
|
+ const Child = defineVaporComponent({
|
|
|
+ setup() {
|
|
|
+ onUnmounted(unmounted)
|
|
|
+ return template('<span>child</span>')()
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const { html } = define(() => {
|
|
|
+ return createFor(
|
|
|
+ () => items.value,
|
|
|
+ () => createComponent(Child),
|
|
|
+ undefined,
|
|
|
+ VaporVForFlags.FAST_REMOVE | VaporVForFlags.IS_COMPONENT,
|
|
|
+ )
|
|
|
+ }).render()
|
|
|
+
|
|
|
+ expect(html()).toBe('<span>child</span><span>child</span><!--for-->')
|
|
|
+
|
|
|
+ items.value = []
|
|
|
+ await nextTick()
|
|
|
+
|
|
|
+ expect(html()).toBe('<!--for-->')
|
|
|
+ expect(unmounted).toHaveBeenCalledTimes(2)
|
|
|
+ })
|
|
|
+
|
|
|
test('slot fallback fragments can be reordered and removed', async () => {
|
|
|
const items = ref([
|
|
|
{ id: 'a', text: 'A' },
|