Open eight04 opened 1 year ago
I agree that the live preview functionality should be overhauled - it's a massive performance hog on my NixOS seemingly running on every single keystroke you do in the style editor, even when just editing a /* comment */
.
The live preview should at least wait for keyboard inactivity for like 1~2 seconds minimum before it keeps spamming reloads.
This refactor isn't about performance, i.e. it won't change noticeably.
The only way to improve performance significantly is to use CSSStyleSheet.cssRules API directly in the affected tabs to patch only the changed rules, but finding the relation between the source text and the injected stylesheet is pretty hard to implement without incurring a big overhead. I'm not that interested eitehr as I've never experienced any slowness on my old i7 CPU.
You can change the delay in the current editor by running the following code in devtools console for the editor:
editor.previewDelay = 2000
I'll add a config for the delay next to the [x] Live preview
checkbox, I guess.
https://github.com/openstyles/stylus/pull/1565#discussion_r1133124966
Currently, usercss live preview is not very efficient. It has to:
Step 2-5 should be moved to background.
we can
previewManager
that handles "raw" style (source code) from the editor.previewManager
would compile the "raw" style and send the result tostyleManager
.styleManager.installPreview()/uninstallPreview()
that can be used bypreviewManager
.Then, we can make
previewManager
listen tostyleUpdated
to re-compile the preview on config change.The editor:
previewManager
.live preview
checkbox)This pattern is similar to how we handle live reload when opening a .user.css file locally. We can probably merge them into a single service. (e.g.
liveInstaller
?)