Fix css preload when serving from proxied subpaths (#9822)

* Fix assets when serving from subpath

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: pngwn <hello@pngwn.io>
This commit is contained in:
Alessandro Molina 2024-11-16 17:54:49 +01:00 committed by GitHub
parent 4d520a8a7b
commit 2e2cdbfb60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/core": patch
"gradio": patch
---
fix:Fix css preload when serving from proxied subpaths

View File

@ -14,9 +14,12 @@ if (
export function mount_css(url: string, target: HTMLElement): Promise<void> { export function mount_css(url: string, target: HTMLElement): Promise<void> {
const base = new URL(import.meta.url).origin; 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}']`); const existing_link = document.querySelector(`link[href='${_url}']`);
if (existing_link) return Promise.resolve(); if (existing_link) return Promise.resolve();
const link = document.createElement("link"); const link = document.createElement("link");