Skip to content

Commit

Permalink
Remove a circular dependency between lite/index.ts and lite/custom-el…
Browse files Browse the repository at this point in the history
…ement/index.ts to solve a bug that the dev app is mounted twice sometimes
  • Loading branch information
whitphx committed Feb 20, 2024
1 parent 1220e3a commit 81de3d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions js/app/src/lite/custom-element/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { create, type Options } from "..";
// NOTE: We should only import the types from ".." to avoid the circular dependency of implementations,
// which causes repeated executions of the ".." module in †he dev mode and can lead to multiple instances of the dev app.
import type { create as createLiteAppFunc, Options } from "..";

interface GradioComponentOptions {
info: Options["info"];
Expand Down Expand Up @@ -28,7 +30,9 @@ function parseRequirementsTxt(content: string): string[] {
.filter((r) => r !== "");
}

export function bootstrap_custom_element(): void {
export function bootstrap_custom_element(
create: typeof createLiteAppFunc
): void {
const CUSTOM_ELEMENT_NAME = "gradio-lite";

if (customElements.get(CUSTOM_ELEMENT_NAME)) {
Expand Down
2 changes: 1 addition & 1 deletion js/app/src/lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export function create(options: Options): GradioAppController {
// @ts-ignore
globalThis.createGradioApp = create;

bootstrap_custom_element();
bootstrap_custom_element(create);

declare let BUILD_MODE: string;
if (BUILD_MODE === "dev") {
Expand Down

0 comments on commit 81de3d5

Please sign in to comment.