From 6e9936531df445050e058cca7ec6f3b7c10b68cd Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sun, 17 Dec 2023 19:45:37 +0800 Subject: [PATCH] fix theme shifting bug --- themes/theme.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/themes/theme.py b/themes/theme.py index ca6ab3a17..5664f7377 100644 --- a/themes/theme.py +++ b/themes/theme.py @@ -70,15 +70,20 @@ def from_cookie_str(c): """ js_code_for_css_changing = """(css) => { + var existingStyles = document.querySelectorAll("body > gradio-app > div > style") + for (var i = 0; i < existingStyles.length; i++) { + var style = existingStyles[i]; + style.parentNode.removeChild(style); + } var existingStyles = document.querySelectorAll("style[data-loaded-css]"); for (var i = 0; i < existingStyles.length; i++) { var style = existingStyles[i]; style.parentNode.removeChild(style); } var styleElement = document.createElement('style'); - styleElement.setAttribute('data-loaded-css', css); + styleElement.setAttribute('data-loaded-css', 'placeholder'); styleElement.innerHTML = css; - document.head.appendChild(styleElement); + document.body.appendChild(styleElement); } """