Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lite worker refactoring #9424

Merged
merged 8 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/chatty-kings-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/lite": patch
"@gradio/wasm": patch
"gradio": patch
---

feat:Lite worker refactoring
9 changes: 8 additions & 1 deletion js/lite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ export function create(options: Options): GradioAppController {
// @ts-ignore
globalThis.createGradioApp = create;

bootstrap_custom_element(create);
// Deferring the custom element registration until the DOM is ready.
// If not, `this.textContent` will be empty in `connectedCallback`
// because the browser has not parsed the content yet.
// Using `setTimeout()` is also a solution but it might not be the best practice as written in the article below.
// Ref: https://dbushell.com/2024/06/15/custom-elements-unconnected-callback/
document.addEventListener("DOMContentLoaded", () => {
bootstrap_custom_element(create);
});

declare let BUILD_MODE: string;
if (BUILD_MODE === "dev") {
Expand Down
2 changes: 0 additions & 2 deletions js/wasm/src/webworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ os.link = lambda src, dst: None

console.debug("Defining a ASGI wrapper function.");
updateProgress("Defining a ASGI wrapper function");
// TODO: Unlike Streamlit, user's code is executed in the global scope,
// so we should not define this function in the global scope.
await pyodide.runPythonAsync(`
# Based on Shiny's App.call_pyodide().
# https://github.com/rstudio/py-shiny/blob/v0.3.3/shiny/_app.py#L224-L258
Expand Down
Loading