From 2e2cdbfb609ca992ccc31bb38589486aaaa14012 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Sat, 16 Nov 2024 17:54:49 +0100 Subject: [PATCH] Fix css preload when serving from proxied subpaths (#9822) * Fix assets when serving from subpath * add changeset --------- Co-authored-by: gradio-pr-bot Co-authored-by: Abubakar Abid Co-authored-by: pngwn --- .changeset/full-pigs-post.md | 6 ++++++ js/core/src/css.ts | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/full-pigs-post.md diff --git a/.changeset/full-pigs-post.md b/.changeset/full-pigs-post.md new file mode 100644 index 0000000000..c7c3fe71ba --- /dev/null +++ b/.changeset/full-pigs-post.md @@ -0,0 +1,6 @@ +--- +"@gradio/core": patch +"gradio": patch +--- + +fix:Fix css preload when serving from proxied subpaths diff --git a/js/core/src/css.ts b/js/core/src/css.ts index ca58de5072..8f0452c4f5 100644 --- a/js/core/src/css.ts +++ b/js/core/src/css.ts @@ -14,9 +14,12 @@ if ( export function mount_css(url: string, target: HTMLElement): Promise { const base = new URL(import.meta.url).origin; - const _url = new URL(url, base).href; + var _url = url; + if (window.location.origin !== base) { + // Serving assets over a CDN, generate absolute url + _url = new URL(url, base).href; + } const existing_link = document.querySelector(`link[href='${_url}']`); - if (existing_link) return Promise.resolve(); const link = document.createElement("link");