Skip to content

Commit

Permalink
Fix issue with head param when adding more than one script tag (#6639)
Browse files Browse the repository at this point in the history
* fix

* Revert "fix"

This reverts commit 86783c8.

* fix

* add changeset

* fix

* add external js file functionality

* format

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
dawoodkhan82 and gradio-pr-bot committed Dec 12, 2023
1 parent 28a7aa9 commit 9a6ff70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/hip-needles-mate.md
@@ -0,0 +1,6 @@
---
"@gradio/app": patch
"gradio": patch
---

fix:Fix issue with `head` param when adding more than one script tag
19 changes: 14 additions & 5 deletions js/app/src/Index.svelte
Expand Up @@ -150,12 +150,21 @@
async function add_custom_html_head(
head_string: string | null
): Promise<void> {
const parser = new DOMParser();
if (head_string) {
const head_html = parser.parseFromString(head_string, "text/html").head
.firstChild;
if (head_html) {
document.head.append(head_html);
const parser = new DOMParser();
const parsed_head_html = Array.from(
parser.parseFromString(head_string, "text/html").head.children
);
if (parsed_head_html) {
for (let head_element of parsed_head_html) {
let newScriptTag = document.createElement("script");
Array.from(head_element.attributes).forEach((attr) => {
newScriptTag.setAttribute(attr.name, attr.value);
});
newScriptTag.textContent = head_element.textContent;
document.head.appendChild(newScriptTag);
}
}
}
}
Expand Down

0 comments on commit 9a6ff70

Please sign in to comment.