-
Notifications
You must be signed in to change notification settings - Fork 313
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
Hot reloading style sheets #156
Comments
Hi, and welcome! Generally, I'd say you have a good understanding of the situation. What I've done is just to reload the whole document (after clearing the cache), but I agree that just updating the style sheet when it changes would be very convenient in many situations. I would very much be open to a PR. So, right now, all the style sheet information, both external and inline are just merged into a single style sheet. We don't really store the origins in an easily accessible manner currently. I'm not sure how best to solve it, because we will have to pull in all external and inline style sheets again and merge them together. I'm thinking perhaps one of these options:
Out of these, I'm favoring number 2. However, I might be overthinking this right now. Let me know if any of this makes sense :) |
Hey thanks for responding so quickly! I figured reloading the whole document would work in some cases but I suppose if the game modifies content on the fly (which seems likely) then it would not retain any of that content :/ So I've dived into the code and I have a couple of remarks/questions:
P.S.: I am truly sorry about the absolute novel I just wrote. |
Appreciate the detailed response. Don't worry about the novel, you show a lot of skill here and I find it all productive :)
4-6. In my own case, I like to store document-specific styles in inline RCSS, so I would find it highly useful if we could reload inline styles as well, without affecting the DOM tree / reloading the whole document. As you say, the latter is a more destructive operation. In the case where a user saves an RML file, they would have to make a choice: Either reload the document entirely, or reload the the style sheet only. In the case of hot reloading, the latter could be done automatically when saving the file, while the former could be done manually. But in any case, this decision would be left to the client. So I guess that is where our priorities differ a bit, it wouldn't personally be as useful to me if I couldn't reload inline style sheets. I'm also a bit worried about storing a lot of data that would only be useful during development. Especially the inline style sheets, they can easily become a sizable amount of data. I'm fine with a list of external resources though. So, my preferred approach would be a method that re-parses the header. This way we would avoid storing the inline style sheets, and we can easily support reloading inline sources as well. |
To be clear my reluctance about reparsing has nothing to do with performance and more to do with structure/philosophy. However I completely understand your points about reloading inline style and the problem of keeping dev things in memory, so let's head the reparsing way! So I started by taking another look at the callstack when getting to It eventually came to mind that I wanted to essentially do
Now this is kind of a bazooka for a (fairly large) fly but since it's a dev feature I could actually use it without feeling bad about it 🤷♀ I've been testing it in the demo sample (refresh every second to avoid dealing with directory watching) and it works like a charm! I was able to seamlessly change inline or external style and it would refresh within the second, without losing any state information. Besides it having relatively bad performance, do you know of any problems that could arise with this solution? Otherwise I think I'm going to go with this for my engine. P.S.: Since it is small and kind of hacky I didn't think you'd want to have that in RmlUi at first but if you do I guess this could be put inside a |
That's actually a pretty creative solution :) I don't really see a reason it shouldn't work, perhaps it may interfere a bit with unexpected client callbacks. And of course it's pretty slow, but it should not be a high priority case. I do see your point that a more dedicated solution would be a bit invasive, we would probably have to modify the XML parser to enable an early exit. We could take this general approach, but make it faster and with less side-effects. Instead of I'd very much be happy with such a function on |
I created PR #159 with the new method as discussed, I don't know if I have to link the issue to it myself? In which case I did not succeed as you can see in the history of the PR :D |
Hello,
I'm currently integrating RmlUi 3.3 to my engine and wanted to try and reload style sheets when they change on disk to have the results directly appear on screen. I've seen
ElementDocument::SetStyleSheet
so I suppose updating the style sheets themselves at runtime is not a problem. I noticed theStyleSheetFactory
has a cache of already parsed style sheets and a method to clear that cache, which seems to go my way, but I have not found any way to ask a document to reload its style sheets, or to clear the style sheet cache for a specific file (or combination with said file). I would gladly clear the whole cache (performance isn't really an issue as it's a dev feature), and then use the factory to recreate the style sheet(s) for my document and set it, but I haven't found a way to know which sources aStyleSheet
uses.Am I missing something or is that a current limitation? If there's anything to do to make it happen I'm willing to work on a PR, it doesn't seem to me (if
SetStyleSheet
updates everything as I suspect) like a whole lot of work, there's only a bit of information missing from the client's perspective.I'm using 3.3 because it's the latest stable version but I will switch as soon as a new version comes out if that helps. I'm very interested in hot reloading as it would greatly help the UI artist's workflow.
Thank you for your time, I'm eager to continue working with this lib :)
The text was updated successfully, but these errors were encountered: