Skip to content

Commit 794b192

Browse files
authored
fix(find): find element inside suspense with multi root elements (#1397)
1 parent d7b1b25 commit 794b192

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/utils/getRootNodes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { isNotNullOrUndefined } from '../utils'
33
import { VNode, VNodeArrayChildren } from 'vue'
44

55
export function getRootNodes(vnode: VNode): Node[] {
6-
if (vnode.shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.SUSPENSE)) {
6+
if (vnode.shapeFlag & ShapeFlags.ELEMENT) {
77
return [vnode.el as Node]
88
} else if (vnode.shapeFlag & ShapeFlags.COMPONENT) {
99
const { subTree } = vnode.component!
1010
return getRootNodes(subTree)
11+
} else if (vnode.shapeFlag & ShapeFlags.SUSPENSE) {
12+
return getRootNodes(vnode.suspense!.activeBranch!)
1113
} else if (
1214
vnode.shapeFlag &
1315
(ShapeFlags.TEXT_CHILDREN | ShapeFlags.TELEPORT)

tests/features/suspense.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SuspenseComponent from '../components/Suspense.vue'
22
import { mount, flushPromises } from '../../src'
3+
import { defineComponent } from 'vue'
34

45
let mockShouldError = false
56
jest.mock('../utils', () => ({
@@ -32,4 +33,30 @@ describe('suspense', () => {
3233

3334
expect(wrapper.html()).toContain('Error!')
3435
})
36+
37+
test('returns the element if it is a multi root element inside Suspense', () => {
38+
const Async = defineComponent({
39+
template: '<h1>Hello</h1><span id="my-span">There</span>'
40+
})
41+
const Component = defineComponent({
42+
components: { Async },
43+
template: '<Suspense><Async/></Suspense>'
44+
})
45+
46+
const wrapper = mount(Component)
47+
expect(wrapper.get('#my-span')).not.toBeNull()
48+
})
49+
50+
test('returns the element if it is a root element inside Suspense', () => {
51+
const Async = defineComponent({
52+
template: '<div><h1>Hello</h1><span id="my-span">There</span></div>'
53+
})
54+
const Component = defineComponent({
55+
components: { Async },
56+
template: '<Suspense><Async/></Suspense>'
57+
})
58+
59+
const wrapper = mount(Component)
60+
expect(wrapper.get('#my-span')).not.toBeNull()
61+
})
3562
})

0 commit comments

Comments
 (0)