2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-12 12:52:24 +03:00

fix: check if DOM is still loading before cleanup

This commit is contained in:
pimlie
2021-05-23 17:59:05 +02:00
parent 14aef1c7d0
commit 1785d4fef6
+11 -5
View File
@@ -177,16 +177,22 @@ export class MetaManager {
if (!isSSR && !this.ssrCleanedUp) {
this.ssrCleanedUp = true
// Listen for DOM loaded because tags in the body couldnt
// have loaded yet once the manager does it first render
// (preferable there should only be one meta render on hydration)
window.addEventListener('DOMContentLoaded', () => {
const cleanUpSSR = () => {
const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`)
if (ssrTags && ssrTags.length) {
ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el))
}
}, { once: true })
}
if (document.readyState === 'loading') {
// Listen for DOM loaded because tags in the body couldnt
// have loaded yet once the manager does it first render
// (preferable there should only be one meta render on hydration)
window.addEventListener('DOMContentLoaded', cleanUpSSR, { once: true })
} else {
cleanUpSSR()
}
}
const teleports: MetaTeleports = {}