Fix issue with virtual module in custom components (#8761)

* fix bug

* add changeset

* fix really

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
pngwn 2024-07-12 18:34:41 +01:00 committed by GitHub
parent 1e8f31b09a
commit 078663a3a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"@gradio/preview": patch
---
fix:Fix issue with virtual module in custom components

View File

@ -69,6 +69,8 @@ export function make_gradio_plugin({
backend_port,
imports
}: GradioPluginOptions): Plugin {
const v_id = "virtual:component-loader";
const resolved_v_id = "\0" + v_id;
return {
name: "gradio",
enforce: "pre",
@ -90,6 +92,9 @@ export function make_gradio_plugin({
};
},
resolveId(id) {
if (id === v_id) {
return resolved_v_id;
}
if (
id !== "svelte" &&
id !== "svelte/internal" &&
@ -98,6 +103,11 @@ export function make_gradio_plugin({
return join(svelte_dir, "svelte-submodules.js");
}
},
load(id) {
if (id === resolved_v_id) {
return `export default {};`;
}
},
transformIndexHtml(html) {
return mode === "dev"
? [

19
pnpm-lock.yaml generated
View File

@ -1688,6 +1688,25 @@ importers:
specifier: ^3.28.0
version: 3.28.0
js/preview/test/mycomponent/frontend:
dependencies:
'@gradio/atoms':
specifier: workspace:^
version: link:../../../../atoms
'@gradio/icons':
specifier: workspace:^
version: link:../../../../icons
'@gradio/statustracker':
specifier: workspace:^
version: link:../../../../statustracker
'@gradio/utils':
specifier: workspace:^
version: link:../../../../utils
devDependencies:
'@gradio/preview':
specifier: workspace:^
version: link:../../..
js/preview/test/test/frontend: {}
js/radio: