Fix theme reloading on gradio-lite demos.
Browse files- templates.py +5 -2
templates.py
CHANGED
|
@@ -64,11 +64,14 @@ def load_js(demo_type: DemoType) -> str:
|
|
| 64 |
|
| 65 |
|
| 66 |
def update_iframe_js(demo_type: DemoType) -> str:
|
| 67 |
-
# TODO: Theme changes are not picked up; look at options to refresh the css.
|
| 68 |
if demo_type == DemoType.GRADIO:
|
| 69 |
return f"""async (code) => {{
|
| 70 |
async function update() {{
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
const newCode = code + ` # Update tag ${{Math.random()}}`;
|
| 73 |
appController.run_code(newCode);
|
| 74 |
}};
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
def update_iframe_js(demo_type: DemoType) -> str:
|
|
|
|
| 67 |
if demo_type == DemoType.GRADIO:
|
| 68 |
return f"""async (code) => {{
|
| 69 |
async function update() {{
|
| 70 |
+
// Remove existing stylesheet so it will be reloaded;
|
| 71 |
+
// see https://github.com/gradio-app/gradio/blob/200237d73c169f39514465efc163db756969d3ac/js/app/src/lite/css.ts#L41
|
| 72 |
+
const demoFrameWindow = document.getElementById('gradio-iframe').contentWindow;
|
| 73 |
+
demoFrameWindow.document.querySelector("head style").remove();
|
| 74 |
+
const appController = demoFrameWindow.window.appController;
|
| 75 |
const newCode = code + ` # Update tag ${{Math.random()}}`;
|
| 76 |
appController.run_code(newCode);
|
| 77 |
}};
|