# Bug #24: Gradio + WebGL/NiiVue Root Cause Analysis **Date:** 2025-12-10 **Status:** ALL `gr.HTML` HACKS FAILED - Custom Component Required **Issue:** HF Spaces stuck on "Loading..." forever **Root Cause:** The `gr.HTML` + `js_on_load` + async `import()` pattern blocks Svelte hydration **Note:** Gradio CAN do WebGL via Custom Components (proven by gradio-litmodel3d) **Solution:** Build Gradio Custom Component (see spec #28) --- ## CONFIRMED: All gr.HTML Hacks Have Failed | Attempt | Date | Result | |---------|------|--------| | CDN import in js_on_load | Dec 9 | FAILED - CSP blocks external imports | | Vendored + dynamic import() in js_on_load | Dec 9 | FAILED - Blocks Svelte hydration | | head_paths with loader HTML | Dec 9 | FAILED - Same hydration issue | | head= with inline import() | Dec 10 | **FAILED** - Confirmed DOA | **There is no hack that works.** The only path forward is spec #28 (Gradio Custom Component). --- ## Why Are We Using Gradio? **What Gradio provides:** - Quick ML demo UIs with Python only (no frontend code needed) - Built-in components: file upload, sliders, dropdowns, image display - Easy deployment to HuggingFace Spaces - Handles backend/frontend communication automatically **What Gradio does NOT provide:** - Native support for NIfTI/DICOM medical imaging (closed as "not planned" - [Issue #4511](https://github.com/gradio-app/gradio/issues/4511)) - Native WebGL canvas component (closed as "not planned" - [Issue #7649](https://github.com/gradio-app/gradio/issues/7649)) - Clean way to embed custom WebGL libraries like NiiVue --- ## The Root Cause: We're Fighting `gr.HTML`, Not Gradio ### What We're Trying To Do Embed NiiVue (a WebGL2 library) into `gr.HTML` using JavaScript. ### Why `gr.HTML` + JavaScript Doesn't Work 1. **`gr.HTML` strips `