perf(nuxt): tree-shake client-only components from ssr bundle #5750
Conversation
β Deploy Preview for nuxt3-docs canceled.
|
<ClientOnly>
contents in ssr bundle
This is a nice to have enhancement but as we discussed and you also mentioned in the description, we have the new method of Is there any case do you think we cannot offer to migrate from |
Even with Moreover, it's not always compatible with best practices in component design. If we have to extract a separate I think it is better to have both options in the code base, for different purposes. |
Fair point about tree-shaking children π Then let's try it :) Off topic: regarding .client vs Client-only, using wrapper beings fragmentation too since developer has to always remember adding wrapper and can easily forget to by mistake... |
<ClientOnly>
contents in ssr bundle6800707
to
f8abd25
Compare
f8abd25
to
91018ac
Compare
π Linked issue
similar, but for composables rather than templates: #5749
together, they resolve nuxt/nuxt#14192
β Type of change
π Description
Vue will still render the slots/children of a client-only component, which often creates the non-intuitive situation that it's not enough to wrap a component that's incompatible with SSR (often a third-party component). Instead, it needs to be used only with in a
~/components/SomeWrapper.client.vue
. But we can do better. This PR strips out any children from client-only components, rendering just the wrapper on SSR.The one caveat is that because we are naively matching
<template>
with RegExp, this will break with nested versions of the same component, e.g.<ClientOnly><ClientOnly></ClientOnly></ClientOnly>
. I think this is an edge case and it's probably enough to warn in the docs, but if we want to support it, I can rewrite to use a different matching method other than RegExp.π Checklist