Skip to content

Commit 612cc18

Browse files
koddssonkeithamus
andcommitted
Observe elements when whenSeen is called
Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
1 parent 49b4cc0 commit 612cc18

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/lazy-define.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ const elementLoader = new MutationObserver(mutations => {
5454
}
5555
}
5656
})
57-
elementLoader.observe(document, {subtree: true, childList: true})
5857

5958
let first = true
6059
export function whenSeen(tagName: string, callback: () => void) {
6160
if (!dynamicElements.has(tagName)) dynamicElements.set(tagName, [])
6261
dynamicElements.get(tagName)!.push(callback)
6362

64-
if (first) scan(document.body)
65-
first = false
63+
if (first) {
64+
scan(document.body)
65+
elementLoader.observe(document, {subtree: true, childList: true})
66+
first = false
67+
}
6668
}

0 commit comments

Comments
 (0)