diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index 20d1f11cbf..25cf790ebc 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -127,13 +127,13 @@ export default defineComponent({ } } - const ssrHTML = ref('') + const cmpKey = `${props.name}_${hashId.value}` + const ssrHTML = ref(nuxtApp.payload.data[cmpKey]?.html || '') - if (import.meta.client && instance.vnode?.el) { + if (import.meta.client && instance.vnode?.el && !ssrHTML.value) { ssrHTML.value = getFragmentHTML(instance.vnode.el, true)?.join('') || '' - const key = `${props.name}_${hashId.value}` - nuxtApp.payload.data[key] ||= {} - nuxtApp.payload.data[key].html = ssrHTML.value + nuxtApp.payload.data[cmpKey] ||= {} + nuxtApp.payload.data[cmpKey].html = ssrHTML.value } const uid = ref(ssrHTML.value.match(SSR_UID_RE)?.[1] ?? getId())