This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
[plugins/unocss] presetUno
significantly slows down CSR hydration
#172
Labels
TLDR: enabling CSR mode will significantly slow-down hydration due primarily to the
presetUno
preset included by thepresetNetzo
preset (same goes forpresetMini()
). At first is was though that this was due to thepresetNetzo
including the entire MDI icons collection, which is then base64-encoded to be loaded as an ESM import in the plugin's entrypoint script which initializes the unocss runtime, but the huge icons bundle is not the issue, but simply thepresetUno
itself, which somewhow slows the unocss' runtimeinit()
function from~500ms
to~30s
.Workaround
The current workaround is to simply delete the
@unocss/preset-uno
registration before setting thewindow.__unocss = config;
(note that this registration could be several levels deep, within other presets).Additionally, the
"safelist"
property is used inpresetNetzo
to force-include all dynamically injected classes for components which mount/unmount dynamically (e.g. dialogs, sheets) so that these also work (more or less) despite having CSR disabled. Additional dynamic classes can always be included in the"safelist"
of theuno.config
file as well. This way,netzo/components
can be used without having to enable CSR mode for thenetzo.unocss
plugin, thus avoiding slowing down hydration.The lists of classes required by each dynamic shadcn component was generated with the following GPT prompt:
Alternatives
We could also try running the unocss runtime off the main thread via partytown, however, we couldn't get that to work easily despite an existing fresh plugin for partytown.
The text was updated successfully, but these errors were encountered: