mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 07:10:34 +03:00
fix: check if DOM is still loading before cleanup
This commit is contained in:
+11
-5
@@ -177,16 +177,22 @@ export class MetaManager {
|
|||||||
if (!isSSR && !this.ssrCleanedUp) {
|
if (!isSSR && !this.ssrCleanedUp) {
|
||||||
this.ssrCleanedUp = true
|
this.ssrCleanedUp = true
|
||||||
|
|
||||||
// Listen for DOM loaded because tags in the body couldnt
|
const cleanUpSSR = () => {
|
||||||
// have loaded yet once the manager does it first render
|
|
||||||
// (preferable there should only be one meta render on hydration)
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`)
|
const ssrTags = document.querySelectorAll(`[${ssrAttribute}]`)
|
||||||
|
|
||||||
if (ssrTags && ssrTags.length) {
|
if (ssrTags && ssrTags.length) {
|
||||||
ssrTags.forEach(el => el.parentNode && el.parentNode.removeChild(el))
|
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 = {}
|
const teleports: MetaTeleports = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user