refactor: Improve tag element selection logic
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 35s

This commit is contained in:
Gauthier Daniels 2025-04-22 13:37:09 +02:00
parent b29acdc202
commit eddc48d284

View File

@ -46,7 +46,12 @@ const findOrCreateTag = <T>(
attributes: Record<string, string>,
): T => {
const head = document.head;
let tag: HTMLElement | null = head.querySelector(tagName);
const attributesString = Object.entries(attributes)
.map(([key, value]) => `${key}="${value}"`)
.join(",");
let tag: HTMLElement | null = head.querySelector(
`${tagName}[${attributesString}]`,
);
if (tag) return tag as T;
tag = document.createElement(tagName);