From ce7845cbcfea41b63e93feab6c67a06ce654a912 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Thu, 18 Jan 2024 23:20:01 +0100 Subject: [PATCH] fix(nuxt): allow omitting `fallback` in island response (#25296) --- packages/nuxt/src/app/components/nuxt-island.ts | 2 +- packages/nuxt/src/core/runtime/nitro/renderer.ts | 4 ++-- test/basic.test.ts | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index 4d9c27b54c..9457099918 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -134,7 +134,7 @@ export default defineComponent({ return html.replaceAll(SLOT_FALLBACK_RE, (full, slotName) => { if (!currentSlots.includes(slotName)) { - return full + payloadSlots[slotName]?.fallback ?? '' + return full + (payloadSlots[slotName]?.fallback || '') } return full }) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index b1e4c20fda..964f76272c 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -64,7 +64,7 @@ export interface NuxtIslandContext { export interface NuxtIslandSlotResponse { props: Array - fallback: string + fallback?: string } export interface NuxtIslandClientResponse { html: string @@ -626,7 +626,7 @@ function getSlotIslandResponse (ssrContext: NuxtSSRContext): NuxtIslandResponse[ for (const slot in ssrContext.islandContext.slots) { response[slot] = { ...ssrContext.islandContext.slots[slot], - fallback: ssrContext.teleports?.[`island-fallback=${slot}`] || '' + fallback: ssrContext.teleports?.[`island-fallback=${slot}`] } } return response diff --git a/test/basic.test.ts b/test/basic.test.ts index ab67992c8c..5294cbf7c0 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -1825,7 +1825,6 @@ describe('component islands', () => { "html": "
count is above 2
that was very long ...
3

hello world !!!

", "slots": { "default": { - "fallback": "", "props": [], }, "fallback": { @@ -1854,7 +1853,6 @@ describe('component islands', () => { ], }, "test": { - "fallback": "", "props": [ { "count": 3,