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

reload on css changes + fix css specificity #6738

Merged
merged 7 commits into from Dec 12, 2023
Merged

reload on css changes + fix css specificity #6738

merged 7 commits into from Dec 12, 2023

Conversation

pngwn
Copy link
Member

@pngwn pngwn commented Dec 11, 2023

Description

This has been driving me up the wall all weekend, so here is a fix.

This should work fine now with no need for !important modifiers or other CSS hacks:

import gradio as gr

css = """
#custom-md h1 {
  color: hotpink;
}

.custom-md h2 {
  color: orange;
}
"""

with gr.Blocks(css=css) as demo:
  gr.Markdown("# Heading one", elem_id="custom-md")
  gr.Markdown("## Heading two", elem_classes=["custom-md"])

demo.launch()

We do this by modifying the selectors passed by a user, prepending them with a series of addition selectors to increase their specificity enough that they override the svelte hashed classes. It's hacky but should be relatively robust.

Closes #6735. Closes #6736.

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Dec 11, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/cfe5f674856711cd15408b80616774720313e920/gradio-4.8.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@cfe5f674856711cd15408b80616774720313e920#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Dec 11, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/app minor
@gradio/preview minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

reload on css changes + fix css specificity

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@pngwn
Copy link
Member Author

pngwn commented Dec 11, 2023

gradio cc dev was completely broken on main because of a dependency issue, I've fixed that in this branch too.

@pngwn
Copy link
Member Author

pngwn commented Dec 12, 2023

Need to merge to check some other issues. Feel free to review and I'll address anything in another PR

@pngwn pngwn merged commit f3c4d78 into main Dec 12, 2023
21 of 22 checks passed
@pngwn pngwn deleted the fix-css branch December 12, 2023 15:32
@pngwn pngwn mentioned this pull request Dec 12, 2023
.join(",");

css_string += rule.cssText;
css_string += rule.cssText.replace(selector, new_selector);
Copy link
Member

Choose a reason for hiding this comment

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

Nice. I don't think repeating a css rule should have any (non-performance-related) downsides so this should be good

Copy link
Member Author

Choose a reason for hiding this comment

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

The number of rules should generally be pretty modest, so I think the performance should be ok.

@abidlabs
Copy link
Member

Cool, looks great to me @pngwn! Thanks for dogfooding this workflow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Writing custom css is frustrating Dev mode does not reload custom css
3 participants