mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-12 12:40:29 +08:00
when adding custom head html, ensure there are no duplicate meta tags (#7510)
* fix: remove old element to prevent duplication remove old element before append new meta tag to prevent duplication * fix: unexpected * Update * format * unexpected * unexpected * add changeset * improve * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
daf40b5ce3
commit
08c2d491ec
6
.changeset/ninety-bars-thank.md
Normal file
6
.changeset/ninety-bars-thank.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/app": patch
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:when adding custom head html, ensure there are no duplicate meta tags
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -19,5 +19,8 @@
|
||||
"eslint.options": {
|
||||
"overrideConfigFile": "./.config/eslint.config.js"
|
||||
},
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"i18n-ally.localesPaths": [
|
||||
"js/app/src/lang"
|
||||
]
|
||||
}
|
||||
|
@ -166,12 +166,35 @@
|
||||
|
||||
if (parsed_head_html) {
|
||||
for (let head_element of parsed_head_html) {
|
||||
let newElement = document.createElement(head_element.tagName);
|
||||
Array.from(head_element.attributes).forEach((attr) => {
|
||||
newElement.setAttribute(attr.name, attr.value);
|
||||
});
|
||||
newElement.textContent = head_element.textContent;
|
||||
document.head.appendChild(newElement);
|
||||
for (let head_element of parsed_head_html) {
|
||||
let newElement = document.createElement(head_element.tagName);
|
||||
Array.from(head_element.attributes).forEach((attr) => {
|
||||
newElement.setAttribute(attr.name, attr.value);
|
||||
});
|
||||
newElement.textContent = head_element.textContent;
|
||||
|
||||
if (
|
||||
newElement.tagName == "META" &&
|
||||
newElement.getAttribute("property")
|
||||
) {
|
||||
const domMetaList = Array.from(
|
||||
document.head.getElementsByTagName("meta") ?? []
|
||||
);
|
||||
const matched = domMetaList.find((el) => {
|
||||
return (
|
||||
el.getAttribute("property") ==
|
||||
newElement.getAttribute("property") &&
|
||||
!el.isEqualNode(newElement)
|
||||
);
|
||||
});
|
||||
if (matched) {
|
||||
document.head.replaceChild(newElement, matched);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
document.head.appendChild(newElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user