diff --git a/.changeset/evil-emus-relax.md b/.changeset/evil-emus-relax.md new file mode 100644 index 000000000000..bcb8ef38efcd --- /dev/null +++ b/.changeset/evil-emus-relax.md @@ -0,0 +1,6 @@ +--- +"@gradio/app": patch +"gradio": patch +--- + +fix:feature detect CSSStylesheet diff --git a/js/app/src/css.ts b/js/app/src/css.ts index da0e5f8c8b9a..d69917f61e06 100644 --- a/js/app/src/css.ts +++ b/js/app/src/css.ts @@ -1,3 +1,16 @@ +let supports_adopted_stylesheets = false; + +if ( + "attachShadow" in Element.prototype && + "adoptedStyleSheets" in Document.prototype +) { + // Both Shadow DOM and adoptedStyleSheets are supported + const shadow_root_test = document + .createElement("div") + .attachShadow({ mode: "open" }); + supports_adopted_stylesheets = "adoptedStyleSheets" in shadow_root_test; +} + export function mount_css(url: string, target: HTMLElement): Promise { const base = new URL(import.meta.url).origin; const _url = new URL(url, base).href; @@ -23,7 +36,8 @@ export function prefix_css( string: string, version: string, style_element = document.createElement("style") -): HTMLStyleElement { +): HTMLStyleElement | null { + if (!supports_adopted_stylesheets) return null; style_element.remove(); const stylesheet = new CSSStyleSheet();