From 800de41c90ae44369df0904041d050af4e88bf2e Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Tue, 19 Mar 2024 19:07:24 +0100 Subject: [PATCH 01/10] fix(nuxt): correctly move v-if from slot to wrapper component --- .../nuxt/src/components/islandsTransform.ts | 4 +++- packages/nuxt/test/islandTransform.test.ts | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts index 5d4f452508f9..062bf384d2e1 100644 --- a/packages/nuxt/src/components/islandsTransform.ts +++ b/packages/nuxt/src/components/islandsTransform.ts @@ -98,10 +98,12 @@ export const islandsTransform = createUnplugin((options: ServerOnlyComponentTran attributes._bind = attributes['v-bind'] delete attributes['v-bind'] } + const vIf = attributes['v-if'] + delete attributes['v-if'] const bindings = getPropsToString(attributes, vfor) // add the wrapper - s.appendLeft(startingIndex + loc[0].start, ``) + s.appendLeft(startingIndex + loc[0].start, ``) s.appendRight(startingIndex + loc[1].end, '') } else if (options.selectiveClient && ('nuxt-client' in node.attributes || ':nuxt-client' in node.attributes)) { hasNuxtClient = true diff --git a/packages/nuxt/test/islandTransform.test.ts b/packages/nuxt/test/islandTransform.test.ts index 821e1877d82a..442cee65e372 100644 --- a/packages/nuxt/test/islandTransform.test.ts +++ b/packages/nuxt/test/islandTransform.test.ts @@ -183,6 +183,29 @@ describe('islandTransform - server and island components', () => { " `) }) + + it('expect v-if to be set in teleport component wrapper', async () => { + const result = await viteTransform(` + + `, 'WithVif.vue', false, true) + + expect(normalizeLineEndings(result)).toMatchInlineSnapshot(` + " + + " + `) + }) }) describe('nuxt-client', () => { From 84b560c8a6767bdcb844a4e5f1a333d42d5d635f Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Tue, 19 Mar 2024 19:20:47 +0100 Subject: [PATCH 02/10] perf: remove v-if from slot --- packages/nuxt/src/components/islandsTransform.ts | 4 ++++ packages/nuxt/test/islandTransform.test.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts index 062bf384d2e1..a9fa061bbad3 100644 --- a/packages/nuxt/src/components/islandsTransform.ts +++ b/packages/nuxt/src/components/islandsTransform.ts @@ -104,6 +104,10 @@ export const islandsTransform = createUnplugin((options: ServerOnlyComponentTran // add the wrapper s.appendLeft(startingIndex + loc[0].start, ``) + // remove v-if from first tag + if (vIf) { + s.overwrite(startingIndex + loc[0].start, startingIndex + loc[0].end, code.slice( startingIndex + loc[0].start, startingIndex + loc[0].end).replace(`v-if="${vIf}"`, '')) + } s.appendRight(startingIndex + loc[1].end, '') } else if (options.selectiveClient && ('nuxt-client' in node.attributes || ':nuxt-client' in node.attributes)) { hasNuxtClient = true diff --git a/packages/nuxt/test/islandTransform.test.ts b/packages/nuxt/test/islandTransform.test.ts index 442cee65e372..d3b7546012e2 100644 --- a/packages/nuxt/test/islandTransform.test.ts +++ b/packages/nuxt/test/islandTransform.test.ts @@ -201,7 +201,7 @@ describe('islandTransform - server and island components', () => { const foo = true; " `) From 72401878c096c4c3658ba20e801aebce8847ab28 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:23:23 +0000 Subject: [PATCH 03/10] [autofix.ci] apply automated fixes --- packages/nuxt/src/components/islandsTransform.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts index a9fa061bbad3..4dcec36a08fa 100644 --- a/packages/nuxt/src/components/islandsTransform.ts +++ b/packages/nuxt/src/components/islandsTransform.ts @@ -106,7 +106,7 @@ export const islandsTransform = createUnplugin((options: ServerOnlyComponentTran s.appendLeft(startingIndex + loc[0].start, ``) // remove v-if from first tag if (vIf) { - s.overwrite(startingIndex + loc[0].start, startingIndex + loc[0].end, code.slice( startingIndex + loc[0].start, startingIndex + loc[0].end).replace(`v-if="${vIf}"`, '')) + s.overwrite(startingIndex + loc[0].start, startingIndex + loc[0].end, code.slice(startingIndex + loc[0].start, startingIndex + loc[0].end).replace(`v-if="${vIf}"`, '')) } s.appendRight(startingIndex + loc[1].end, '') } else if (options.selectiveClient && ('nuxt-client' in node.attributes || ':nuxt-client' in node.attributes)) { From 889a99fc1a055e71a4a5e1bce2d10de4d61610dd Mon Sep 17 00:00:00 2001 From: julien huang Date: Sat, 23 Mar 2024 18:02:30 +0100 Subject: [PATCH 04/10] fix: add else and else-if directives --- .../nuxt/src/components/islandsTransform.ts | 47 ++++++++++++------- packages/nuxt/test/islandTransform.test.ts | 14 ++++-- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts index 4dcec36a08fa..47d8baf91d12 100644 --- a/packages/nuxt/src/components/islandsTransform.ts +++ b/packages/nuxt/src/components/islandsTransform.ts @@ -34,6 +34,7 @@ const HAS_SLOT_OR_CLIENT_RE = /(]*>)|(nuxt-client)/ const TEMPLATE_RE = /