Skip to content

Commit

Permalink
chore: fix devServer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Dec 11, 2023
1 parent 948fa64 commit 029e747
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/client/src/setupUpdateHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export const setupUpdateHead = (): void => {

// load current head tags from DOM
const loadHead = (): void => {
managedHeadElements.push(
...(head.value.map(queryHeadElement).filter(Boolean) as HTMLElement[]),
)
head.value.map(queryHeadElement).forEach((el) => {
if (el && managedHeadElements.every((head) => !head.isEqualNode(el))) {
managedHeadElements.push(el)
}
})
}

// update html lang attribute and head tags to DOM
Expand All @@ -53,11 +55,11 @@ export const setupUpdateHead = (): void => {
(newEl) => newEl?.isEqualNode(el ?? null),
)

if (matchedIndex !== -1) {
delete newHeadElements[matchedIndex]
} else {
if (matchedIndex === -1) {
el?.remove()
delete managedHeadElements[index]
} else {
delete newHeadElements[matchedIndex]
}
})

Expand All @@ -70,7 +72,14 @@ export const setupUpdateHead = (): void => {

onMounted(() => {
loadHead()
watch(() => head.value, updateHead)
if (__VUEPRESS_DEV__) updateHead()
watch(
() => head.value,
() => {
if (__VUEPRESS_DEV__) loadHead()
updateHead()
},
)
})
}

Expand Down

0 comments on commit 029e747

Please sign in to comment.