VibecoderMcSwaggins commited on
Commit
b9919fb
·
1 Parent(s): 39b452a

docs: add bug report for intermittent gradio loading issues

Browse files
docs/bugs/004_gradio_intermittent_loading.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Bug Report: Intermittent Gradio UI Loading (Hydration/Timeout)
2
+
3
+ ## 1. Symptoms
4
+ - **Intermittent Loading**: The UI sometimes fails to load, showing a blank screen or a "Connection Error" toast.
5
+ - **Refresh Required**: Users often have to hard refresh the page (Ctrl+Shift+R) multiple times to get the UI to appear.
6
+ - **Mobile vs. Desktop**: The issue appears to be more prevalent or noticeable on Desktop Web than on Mobile Web (possibly due to network conditions, caching, or layout differences).
7
+ - **Environment**: HuggingFace Spaces (Docker SDK).
8
+
9
+ ## 2. Root Cause Analysis
10
+
11
+ Based on research into Gradio 5.x/6.x behavior on HuggingFace Spaces, this is likely due to a combination of:
12
+
13
+ ### A. SSR (Server-Side Rendering) Hydration Mismatch
14
+ Gradio 5+ introduced Server-Side Rendering (SSR) to improve initial load performance. However, on HuggingFace Spaces (which uses an iframe), there can be race conditions where the server-rendered HTML doesn't match what the client-side JavaScript expects, causing a "Hydration Error". When this happens, the React/Svelte frontend crashes silently or enters an inconsistent state, requiring a full refresh.
15
+
16
+ ### B. WebSocket Timeouts
17
+ HuggingFace Spaces enforces strict timeouts for WebSocket connections. If the app takes too long to initialize (e.g., loading heavy libraries or models), the initial handshake may fail.
18
+ - *Mitigation*: Our app is relatively lightweight on startup (lazy loading models), so this is secondary, but network latency can trigger it.
19
+
20
+ ### C. Browser Caching
21
+ Aggressive browser caching of the main bundle can sometimes cause version mismatches if the Space was recently rebuilt/redeployed.
22
+
23
+ ## 3. Proposed Solution
24
+
25
+ ### Immediate Fix: Disable SSR
26
+ Forcing Client-Side Rendering (CSR) eliminates the hydration mismatch entirely. While this theoretically slightly slows down the "First Contentful Paint", it is much more robust for dynamic apps inside iframes.
27
+
28
+ **Change in `src/app.py`:**
29
+ ```python
30
+ demo.launch(
31
+ # ... other args ...
32
+ ssr_mode=False, # Force Client-Side Rendering to fix hydration issues
33
+ )
34
+ ```
35
+
36
+ ### Secondary Fixes (If needed)
37
+ - **Increase Concurrency Limits**: Ensure `max_threads` is sufficient if many users connect at once.
38
+ - **Health Check**: Add a simple lightweight endpoint to keep the Space "warm" if it sleeps aggressively.
39
+
40
+ ## 4. Verification Plan
41
+ 1. Apply `ssr_mode=False` to `src/app.py`.
42
+ 2. Deploy to HuggingFace Spaces (`fix/gradio-ui-final` branch).
43
+ 3. Test on Desktop (Chrome Incognito, Firefox) and Mobile.
44
+ 4. Verify no "Connection Error" toasts appear on initial load.