Fix the Lite custom element parser so it doesn't add the .code option when the entrypoint file is already specified (#8067)

* Fix the Lite custom element parser so it doesn't add the .code option when the entrypoint file is already specified

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2024-04-19 22:26:42 +01:00 committed by GitHub
parent 176a8a4d71
commit 0fb058ec23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 16 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/app": minor
"gradio": minor
---
feat:Fix the Lite custom element parser so it doesn't add the .code option when the entrypoint file is already specified

View File

@ -151,24 +151,29 @@ export function bootstrap_custom_element(
}
}
const codeElements = this.getElementsByTagName("gradio-code");
if (codeElements.length === 0) {
// If there is no <gradio-code> element, try to parse the content of the custom element as code.
let code = "";
this.childNodes.forEach((node) => {
if (node.nodeType === Node.TEXT_NODE) {
code += node.textContent;
if (options.entrypoint == null) {
// If no entrypoint file is specified,
// try to find the source code to be passed to the .code option instead.
const codeElements = this.getElementsByTagName("gradio-code");
if (codeElements.length === 0) {
// If there is no <gradio-code> element, try to parse the content of the custom element as code.
let code = "";
this.childNodes.forEach((node) => {
if (node.nodeType === Node.TEXT_NODE) {
code += node.textContent;
}
});
options.code = code || undefined;
} else {
if (codeElements.length > 1) {
console.warn(
"Multiple <gradio-code> elements are found. Only the first one will be used."
);
}
});
options.code = code || undefined;
} else {
if (codeElements.length > 1) {
console.warn(
"Multiple <gradio-code> elements are found. Only the first one will be used."
);
const firstCodeElement = codeElements[0];
options.code = firstCodeElement?.textContent ?? undefined;
}
const firstCodeElement = codeElements[0];
options.code = firstCodeElement?.textContent ?? undefined;
}
const requirementsElements = this.getElementsByTagName(