Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .changeset/ready-symbols-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/core": patch
"gradio": patch
---

fix:Fix custom component reload mode
2 changes: 0 additions & 2 deletions js/core/src/MountComponents.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import MountCustomComponent from "./MountCustomComponent.svelte";
let { node, ...rest } = $props();

$inspect(node);

let component = $derived(await node.component);
</script>

Expand Down
39 changes: 20 additions & 19 deletions js/core/src/MountCustomComponent.svelte
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
<script lang="ts">
import { onMount, onDestroy } from "svelte";
let { node, children, ...rest } = $props();

let component = $derived(await node.component);
let runtime = $derived(
(await node.runtime) as {
mount: typeof import("svelte").mount;
umount: typeof import("svelte").unmount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuuuumount

unmount: typeof import("svelte").unmount;
}
);
let el: HTMLElement = $state(null);
let comp;

$effect(() => {
console.log({ el, comp, runtime });
if (el && !comp && runtime) {
comp = runtime.mount(component.default, {
target: el,
if (!el || !runtime || !component) return;

props: {
shared_props: node.props.shared_props,
props: node.props.props,
children
}
});
}
});
// Read prop references so the effect re-runs when the node is
// replaced during a dev reload (new objects are created by
// app_tree.reload).
const _shared_props = node.props.shared_props;
const _props = node.props.props;
const _runtime = runtime;

onDestroy(() => {
if (comp) {
runtime.umount(comp);
}
const mounted = _runtime.mount(component.default, {
target: el,
props: {
shared_props: _shared_props,
props: _props,
children
}
});

return () => {
_runtime.unmount(mounted);
};
});
</script>

Expand Down
Loading