fix theme shifting bug

This commit is contained in:
binary-husky 2023-12-17 19:45:37 +08:00
parent 439147e4b7
commit 6e9936531d

View File

@ -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);
}
"""