From b16c2d3ad81b405ef089bd3daf69b36738a67249 Mon Sep 17 00:00:00 2001 From: "jhuang@hsk-partners.com" Date: Tue, 16 Aug 2022 13:49:49 +0200 Subject: [PATCH 1/3] fix(nuxt): fix treeshaking client only regex --- packages/nuxt/src/components/tree-shake.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/components/tree-shake.ts b/packages/nuxt/src/components/tree-shake.ts index 434e41b8318..dcd1bb638cf 100644 --- a/packages/nuxt/src/components/tree-shake.ts +++ b/packages/nuxt/src/components/tree-shake.ts @@ -35,7 +35,7 @@ export const TreeShakeTemplatePlugin = createUnplugin((options: TreeShakeTemplat const s = new MagicString(code) // Do not render client-only slots on SSR, but preserve attributes - s.replace(COMPONENTS_RE, r => r.replace(/<([^ >]*)[ >][\s\S]*$/, '<$1 />')) + s.replace(COMPONENTS_RE, r => r.replace(/<([^>]*)(>|[/>])[\s\S]*$/, '<$1 />')) if (s.hasChanged()) { return { From 9a6182b312e5846d6b9bc5b4722be7578b801b3d Mon Sep 17 00:00:00 2001 From: Julien Huang <63512348+huang-julien@users.noreply.github.com> Date: Tue, 16 Aug 2022 14:21:56 +0200 Subject: [PATCH 2/3] fix(nuxt): fix treeshaking regex Co-authored-by: Daniel Roe --- packages/nuxt/src/components/tree-shake.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/components/tree-shake.ts b/packages/nuxt/src/components/tree-shake.ts index dcd1bb638cf..827506a0ce4 100644 --- a/packages/nuxt/src/components/tree-shake.ts +++ b/packages/nuxt/src/components/tree-shake.ts @@ -35,7 +35,7 @@ export const TreeShakeTemplatePlugin = createUnplugin((options: TreeShakeTemplat const s = new MagicString(code) // Do not render client-only slots on SSR, but preserve attributes - s.replace(COMPONENTS_RE, r => r.replace(/<([^>]*)(>|[/>])[\s\S]*$/, '<$1 />')) + s.replace(COMPONENTS_RE, r => r.replace(/<([^>]*[^\/])\/?>[\s\S]*$/, '<$1 />')) if (s.hasChanged()) { return { From 1e39273b617185e3648db275bf730ef86a0a0534 Mon Sep 17 00:00:00 2001 From: "jhuang@hsk-partners.com" Date: Tue, 16 Aug 2022 14:25:50 +0200 Subject: [PATCH 3/3] refactor: lint --- packages/nuxt/src/components/tree-shake.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/components/tree-shake.ts b/packages/nuxt/src/components/tree-shake.ts index 827506a0ce4..c6273e30ab9 100644 --- a/packages/nuxt/src/components/tree-shake.ts +++ b/packages/nuxt/src/components/tree-shake.ts @@ -35,7 +35,7 @@ export const TreeShakeTemplatePlugin = createUnplugin((options: TreeShakeTemplat const s = new MagicString(code) // Do not render client-only slots on SSR, but preserve attributes - s.replace(COMPONENTS_RE, r => r.replace(/<([^>]*[^\/])\/?>[\s\S]*$/, '<$1 />')) + s.replace(COMPONENTS_RE, r => r.replace(/<([^>]*[^/])\/?>[\s\S]*$/, '<$1 />')) if (s.hasChanged()) { return {