Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wasm_proxied_mount_css to not reuse an existing style element #7709

Merged
merged 2 commits into from Mar 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions js/app/src/lite/css.ts
Expand Up @@ -35,10 +35,11 @@ export async function wasm_proxied_mount_css(
});
const css = new TextDecoder().decode(response.body);

const existing_link = document.querySelector(
// Gradio Lite can be reloaded without refreshing the page, so we need to remove the existing style element if it exists.
const existing_style = document.querySelector(
`style[data-wasm-path='${url_string}']`
);
if (existing_link) return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was implemented after the non-Wasm ver. which skips mounting the CSS if there is always a mounted element as below.

gradio/js/app/src/css.ts

Lines 17 to 19 in 28342a2

const existing_link = document.querySelector(`link[href='${_url}']`);
if (existing_link) return Promise.resolve();

However, Lite is different from the normal one in that the app can be executed repeatedly and the frontend can be refreshed many times, so this design was not correct and the requested CSS must be mounted, replacing the old one.

existing_style?.remove();

if (url.pathname === DYNAMIC_THEME_CSS_URL_PATH) {
console.debug(
Expand Down