-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(nuxt): parse html to treeshake client-only components #7527
Conversation
β Deploy Preview for nuxt3-docs canceled.
|
I will look into jiti issue. Isn't there an easy way to fix the regex issue? Parse5, even if super fast is stil parsing the strings. We might use a hybrid method (like mlly) to improve precision. |
Indeed I could fix that particular issue with regexp but I feel parsing the HTML is more reliable. For example, there was always the caveat of nested client-only components. At some point you reinvent the parser. And I believe parse5 will soon be exposed to us by vite, so we can even benefit from vite caching ast (iirc): vitejs/vite#9678 |
Yes, I'm aware that vite itself is using parse5 and it is a really good decision. But here we are (re) parsing the same template code into AST in a plugin for a particular optimization that benefits only some components. Full parsing makes the built-time overall slower. If there are finally more edge cases that we cannot handle with regex only, same as mlly we can use a two phase detection with quick regex matcher and precision AST (or Tokenized) verifier when we really are going to make a change to the code. It would be nice if first could resolve the linked issue via regex and keep working on this PR as a general enhancenment. |
@danielroe Anyway we can workaround nuxt/nuxt#14896 regex issue? |
~> #7659 |
Updating this PR just to keep it in sync. You were right to be careful; |
π Switched to ultrahtml, a 1.75kB library with zero dependencies and deliberate support for parsing Vue. |
π Linked issue
resolves nuxt/nuxt#14896
β Type of change
π Description
This switches from regexp -> parse5 (fast HTML parsing) to remove client only component nodes. It's more stable and also allows us to preserve fallback slots, for example.
The blocker for this PR is currently unjs/jiti#84; jiti is having trouble transforming
parse5
, blocking testing.π Checklist