mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-08 01:42:38 +00:00
fix(nuxt): assign slot to be rendered for client components (#30768)
This commit is contained in:
parent
31e2570de1
commit
01f5694408
@ -674,7 +674,7 @@ function getServerComponentHTML (body: [string, ...string[]]): string {
|
||||
|
||||
const SSR_SLOT_TELEPORT_MARKER = /^uid=([^;]*);slot=(.*)$/
|
||||
const SSR_CLIENT_TELEPORT_MARKER = /^uid=([^;]*);client=(.*)$/
|
||||
const SSR_CLIENT_SLOT_MARKER = /^island-slot=[^;]*;(.*)$/
|
||||
const SSR_CLIENT_SLOT_MARKER = /^island-slot=([^;]*);(.*)$/
|
||||
|
||||
function getSlotIslandResponse (ssrContext: NuxtSSRContext): NuxtIslandResponse['slots'] {
|
||||
if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.slots).length) { return undefined }
|
||||
@ -698,21 +698,21 @@ function getClientIslandResponse (ssrContext: NuxtSSRContext): NuxtIslandRespons
|
||||
response[clientUid] = {
|
||||
...component,
|
||||
html,
|
||||
slots: getComponentSlotTeleport(ssrContext.teleports ?? {}),
|
||||
slots: getComponentSlotTeleport(clientUid, ssrContext.teleports ?? {}),
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
function getComponentSlotTeleport (teleports: Record<string, string>) {
|
||||
function getComponentSlotTeleport (clientUid: string, teleports: Record<string, string>) {
|
||||
const entries = Object.entries(teleports)
|
||||
const slots: Record<string, string> = {}
|
||||
|
||||
for (const [key, value] of entries) {
|
||||
const match = key.match(SSR_CLIENT_SLOT_MARKER)
|
||||
if (match) {
|
||||
const [, slot] = match
|
||||
if (!slot) { continue }
|
||||
const [, id, slot] = match
|
||||
if (!slot || clientUid !== id) { continue }
|
||||
slots[slot] = value
|
||||
}
|
||||
}
|
||||
|
@ -1946,6 +1946,7 @@ describe('server components/islands', () => {
|
||||
// test islands mounted client side with slot
|
||||
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('Sugar Counter')
|
||||
|
||||
// test islands wrapped with client-only
|
||||
expect(await page.locator('#wrapped-client-only').innerHTML()).toContain('Was router enabled')
|
||||
|
Loading…
Reference in New Issue
Block a user