fix(nuxt): fetch non-server rendered islands when hydrating (#25613)

This commit is contained in:
Julien Huang 2024-02-05 11:36:20 +01:00 committed by GitHub
parent 8705aed8b4
commit 7dd0225007
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 6 deletions

View File

@ -224,9 +224,9 @@ export default defineComponent({
watch(props, debounce(() => fetchComponent(), 100), { deep: true }) watch(props, debounce(() => fetchComponent(), 100), { deep: true })
} }
if (import.meta.client && !nuxtApp.isHydrating && props.lazy) { if (import.meta.client && !instance.vnode.el && props.lazy) {
fetchComponent() fetchComponent()
} else if (import.meta.server || !nuxtApp.isHydrating || !nuxtApp.payload.serverRendered) { } else if (import.meta.server || !instance.vnode.el || !nuxtApp.payload.serverRendered) {
await fetchComponent() await fetchComponent()
} else if (selectiveClient && canLoadClientComponent.value) { } else if (selectiveClient && canLoadClientComponent.value) {
await loadComponents(props.source, payloads.components) await loadComponents(props.source, payloads.components)

View File

@ -1530,6 +1530,9 @@ describe('server components/islands', () => {
await page.locator('#show-island').click() await page.locator('#show-island').click()
expect(await page.locator('#island-mounted-client-side').innerHTML()).toContain('Interactive testing slot post SSR') expect(await page.locator('#island-mounted-client-side').innerHTML()).toContain('Interactive testing slot post SSR')
// test islands wrapped with client-only
expect(await page.locator('#wrapped-client-only').innerHTML()).toContain('Was router enabled')
if (!isWebpack) { if (!isWebpack) {
// test client component interactivity // test client component interactivity
expect(await page.locator('.interactive-component-wrapper').innerHTML()).toContain('Sugar Counter 12') expect(await page.locator('.interactive-component-wrapper').innerHTML()).toContain('Sugar Counter 12')

View File

@ -20,10 +20,14 @@ const count = ref(0)
name="PureComponent" name="PureComponent"
:props="islandProps" :props="islandProps"
/> />
<NuxtIsland <div id="wrapped-client-only">
name="PureComponent" <ClientOnly>
:props="islandProps" <NuxtIsland
/> name="PureComponent"
:props="islandProps"
/>
</ClientOnly>
</div>
</div> </div>
<button <button
id="increase-pure-component" id="increase-pure-component"