Skip to content

Commit

Permalink
Fix mutation strategy when loaded async (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Mohrbacher <lukas.mohrbacher.extern@hornbach.com>
  • Loading branch information
morbidick and Lukas Mohrbacher authored Sep 22, 2022
1 parent 58b180d commit 9be5eee
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/strategies/mutation_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,23 @@ export function defineElement(elSpec, elName, events) {
subtree: true
})

observers[name] = /* true */ observer
observers[elName] = /* true */ observer

window.addEventListener('DOMContentLoaded', () => {
const nodes = document.getElementsByTagName(name)
function mountElementsInDOM() {
const nodes = document.getElementsByTagName(elName)
each(nodes, (/** @type HTMLElement */ node) =>
checkForMount(node, name, events)
checkForMount(node, elName, events)
)
})
}

if (
document.readyState === 'complete' ||
document.readyState === 'interactive'
) {
mountElementsInDOM()
} else {
window.addEventListener('DOMContentLoaded', mountElementsInDOM)
}
}

/**
Expand Down

0 comments on commit 9be5eee

Please sign in to comment.