From 900872769e9adb1e9fe2f0008c500c4367bee3d4 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 21 Jan 2024 00:36:20 +0530 Subject: [PATCH] refactor: simplify head tracking logic --- src/client/app/composables/head.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/client/app/composables/head.ts b/src/client/app/composables/head.ts index d0000a3ccc4b..708c16eb42bf 100644 --- a/src/client/app/composables/head.ts +++ b/src/client/app/composables/head.ts @@ -17,14 +17,13 @@ export function useUpdateHead(route: Route, siteDataByRouteRef: Ref) { // skip the first update. isFirstUpdate = false newTags.forEach((tag) => { - const selector = toSelector(tag[0], tag[1]) const headEl = createHeadElement(tag) - ;[...document.querySelectorAll(selector)].some((el) => { + for (const el of document.head.children) { if (el.isEqualNode(headEl)) { managedHeadElements.push(el as HTMLElement) - return true + return } - }) + } }) return } @@ -106,9 +105,3 @@ function isMetaDescription(headConfig: HeadConfig) { function filterOutHeadDescription(head: HeadConfig[]) { return head.filter((h) => !isMetaDescription(h)) } - -function toSelector(tag: string, attrs: Record) { - return `${tag}${Object.keys(attrs) - .map((key) => `[${key}="${attrs[key].replace(/(["'\\])/g, '\\$1')}"]`) - .join('')}` -}