Skip to content

Commit 1d8ae31

Browse files
author
arnoson
committed
fix: correctly assign deep refs
1 parent 3865288 commit 1d8ae31

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/refs.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@ export const getRefs = (el: HTMLElement) => {
1010

1111
walkComponent(el, el => {
1212
const { ref } = el.dataset
13-
if (ref) addRef(ref, el)
13+
if (!ref) return
14+
15+
const isDeepRef = ref.includes('/')
16+
if (isDeepRef) return
17+
18+
addRef(ref, el)
1419
})
1520

21+
// Deep refs can't be handled during DOM walk, since we stop at child
22+
// components.
1623
const deepRefs = el.querySelectorAll<HTMLElement>('[data-ref*="/"]')
1724
deepRefs.forEach(refEl => {
1825
const [parent, name] = refEl.dataset.ref!.split('/')
1926

2027
const selector = parent.match(/^\((.*)\)$/)?.[1]
2128
const parentSelector = selector ?? `[data-simple-component='${parent}']`
2229

23-
const parentEl = el.closest(parentSelector)
30+
const parentEl = refEl.closest(parentSelector)
2431
if (parentEl === el) addRef(name, refEl)
2532
})
2633

0 commit comments

Comments
 (0)