Skip to content

Commit

Permalink
Fix mutation strategy when loaded async
Browse files Browse the repository at this point in the history
* use correct element name
* also mount elements in DOM when page is already loaded
  • Loading branch information
Lukas Mohrbacher committed May 5, 2020
1 parent 39bd244 commit c1728fd
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 c1728fd

Please sign in to comment.