-
Notifications
You must be signed in to change notification settings - Fork 4
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
[Yew integration] Styles cleanup on component redraw #22
Comments
I was looking into this crate for Yew styling as well, and I noticed the same issue. Any time Line 85 in 51926c7
There is a lazy_static global registry that stores all created styles,Lines 19 to 21 in 51926c7
Lines 91 to 93 in 51926c7
but it is never accessed/modified anywhere else. Perhaps this is the beginnings of such a feature that hasn't been fleshed out yet? I think a limitation of this design is that all Maybe there should be a macro that binds to its source location? Well, that wouldn't allow for dynamic styles... Maybe the classname slug should depend on the hash of the style's contents? Maybe combine with source-location-macro to guard against collision? I haven't done nearly enough research on CSS-in-JS solutions for implementation reference, I'm just spitballing |
The concrete |
Or maybe return some kind of If the registry did reference counting, you could ensure that styles are removed from the document when no component refers to them anymore. This may not always be desirable, but it might keep larger SPA apps from bloating with styles that are only required, say, on one specific route. Perhaps this could be configurable? If |
I'm saying "public method" here, because I assume that the current design continues to hide the global Maybe instead of a hard-coded |
I don't mean to bust in and leave a pile of "here's some demands for some seriously complicated API changes ok bye!" I'm interested in helping out with implementation, if so desired. I'd wind up writing my own thing and spinning off into outer space with complicated features all by myself with nobody to sanity check against, otherwise. That sounds like a lot of duplicated effort and not much fun :) @lukidoescode, I'd be interested in your thoughts. I didn't anticipate writing a novel, but these kinds of considerations have been following me around a lot recently. |
Hi @EndilWayfare, thank you for sharing your thoughts. You can always open up a PR and I will gladly integrate it. Please make sure you add yourself to the list of authors in there. I think the example isn't working because Yew is currently in rapid development and changing all the time. I still need to find a way to add the ability to work with multiple versions of Yew. I myself am too much a beginner with Rust for tackling this big of a task. This library is an idea of mine, a concept if you'd like. I'm currently trying to gather the financial resources for making it a real thing to be up to date all the time. Unfortunately until that time I have to rely on PRs to add functionality and for sometimes making css_in_rust up to date with Yew since I am unfortunately very constrained for time :( |
Hey, @lukidoescode! Yeah, there's never enough hours in the day, I hear ya. I've never published an open-source crate; all my work is proprietary, internal company software. As far as I can tell, this isn't Yew-specific. This issue should show up wherever a Just so I understand your design, is there supposed to be a place where styles are ever dropped or deduplicated? |
Oh, yeah, now I see. Thanks a lot for reporting! I will fix it as soon as I'll have some time left ✌🏼 It should of course remove unused style nodes. I'm curious about how future me will fix that 🤭😋 |
Hopefully this is helpful. I threw this code together with the intention of proving out the concepts from this discussion before writing up a real PR. I figured I should post it here in case I don't get a chance to actually write the PR though.
Main Pieces:
|
Just glancing over it, that looks like a promising start! I may draft a PR of my own, whoever gets around to it first, I guess :) Some thoughts:
|
Thanks for taking a look @EndilWayfare . That's a good point about For the collision case, I agree with "not worth it™", I was also thinking that if the user knew they had a case like this, they can always change the prefix to Random to prevent this. |
I think it's wise to keep code as similar as possible between platforms, deviating only where absolutely necessary or where there are significant "wins" (performance or otherwise). This should make testing easier, developer mental overhead lower, and "exported complexity" to dependent crates minimal. There's precedent for maintaining parallel The The other potential downside of |
Hi lukidoescode!
Thank you for this crate, I find it very useful and like the approach coming from css-in-js in React world.
I am facing the following problem: it seems that the stale styles added to page head by the component rendering are not being removed/replaced when component gets redrawn. This leads to increasing number of nodes in the page and eventually it slows down.
I use Yew integration as suggested in the example and not sure if this is a problem with css_in_rust or yew itself? Can I somehow clean it myself?
Thanks for any suggestions.
The text was updated successfully, but these errors were encountered: