Skip to content

Commit 9008727

Browse files
committed
refactor: simplify head tracking logic
1 parent ba3c644 commit 9008727

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Diff for: src/client/app/composables/head.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ export function useUpdateHead(route: Route, siteDataByRouteRef: Ref<SiteData>) {
1717
// skip the first update.
1818
isFirstUpdate = false
1919
newTags.forEach((tag) => {
20-
const selector = toSelector(tag[0], tag[1])
2120
const headEl = createHeadElement(tag)
22-
;[...document.querySelectorAll(selector)].some((el) => {
21+
for (const el of document.head.children) {
2322
if (el.isEqualNode(headEl)) {
2423
managedHeadElements.push(el as HTMLElement)
25-
return true
24+
return
2625
}
27-
})
26+
}
2827
})
2928
return
3029
}
@@ -106,9 +105,3 @@ function isMetaDescription(headConfig: HeadConfig) {
106105
function filterOutHeadDescription(head: HeadConfig[]) {
107106
return head.filter((h) => !isMetaDescription(h))
108107
}
109-
110-
function toSelector(tag: string, attrs: Record<string, string>) {
111-
return `${tag}${Object.keys(attrs)
112-
.map((key) => `[${key}="${attrs[key].replace(/(["'\\])/g, '\\$1')}"]`)
113-
.join('')}`
114-
}

0 commit comments

Comments
 (0)