refactor: Improve tag element selection logic
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 35s
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 35s
This commit is contained in:
parent
b29acdc202
commit
eddc48d284
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user