Fix blank UI from root-mounted Gradio SSR
Browse filesDisable Gradio 5.49.1 SSR for the root-mounted FastAPI app and add a regression test that verifies a frontend asset referenced by the root page is served successfully.
- app.py +4 -1
- test_app.py +16 -0
app.py
CHANGED
|
@@ -195,7 +195,10 @@ def oauth_login():
|
|
| 195 |
return response
|
| 196 |
|
| 197 |
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
|
| 201 |
if __name__ == "__main__":
|
|
|
|
| 195 |
return response
|
| 196 |
|
| 197 |
|
| 198 |
+
# Gradio 5.49.1's Spaces SSR proxy corrupts frontend asset URLs when a Blocks
|
| 199 |
+
# app is mounted at the root path. OAuth still needs the explicit FastAPI mount,
|
| 200 |
+
# so disable SSR here until the upstream root-mount routing bug is fixed.
|
| 201 |
+
app = gr.mount_gradio_app(app, demo, path="/", ssr_mode=False)
|
| 202 |
|
| 203 |
|
| 204 |
if __name__ == "__main__":
|
test_app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import importlib
|
| 2 |
import os
|
|
|
|
| 3 |
from types import SimpleNamespace
|
| 4 |
|
| 5 |
from fastapi.testclient import TestClient
|
|
@@ -40,3 +41,18 @@ def test_auth_control_uses_top_level_navigation():
|
|
| 40 |
assert 'href="/logout?_target_url=/"' in logged_in
|
| 41 |
assert "<script>" not in logged_in
|
| 42 |
assert "<script>" in logged_in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import importlib
|
| 2 |
import os
|
| 3 |
+
import re
|
| 4 |
from types import SimpleNamespace
|
| 5 |
|
| 6 |
from fastapi.testclient import TestClient
|
|
|
|
| 41 |
assert 'href="/logout?_target_url=/"' in logged_in
|
| 42 |
assert "<script>" not in logged_in
|
| 43 |
assert "<script>" in logged_in
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_root_frontend_asset_is_served():
|
| 47 |
+
"""Catch broken asset paths when mounting Gradio at the Space root."""
|
| 48 |
+
with TestClient(certificate_app.app) as client:
|
| 49 |
+
response = client.get("/")
|
| 50 |
+
assert response.status_code == 200
|
| 51 |
+
|
| 52 |
+
assets = re.findall(r'(?:src|href)="(\.?/assets/[^"]+)"', response.text)
|
| 53 |
+
assert assets, "root page did not reference a Gradio frontend asset"
|
| 54 |
+
|
| 55 |
+
asset_path = assets[0].removeprefix(".")
|
| 56 |
+
asset_response = client.get(asset_path)
|
| 57 |
+
|
| 58 |
+
assert asset_response.status_code == 200
|