diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index de9f581095..66978ef658 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -110,7 +110,7 @@ export default defineComponent({ const key = `${props.name}_${hashId.value}` if (nuxtApp.payload.data[key] && !force) { return nuxtApp.payload.data[key] } - const url = remoteComponentIslands && props.source ? new URL(`/__nuxt_island/${key}`, props.source).href : `/__nuxt_island/${key}` + const url = remoteComponentIslands && props.source ? new URL(`/__nuxt_island/${key}.json`, props.source).href : `/__nuxt_island/${key}.json` if (import.meta.server && import.meta.prerender) { // Hint to Nitro to prerender the island component diff --git a/packages/nuxt/src/app/plugins/revive-payload.client.ts b/packages/nuxt/src/app/plugins/revive-payload.client.ts index 515311b554..3020af1b62 100644 --- a/packages/nuxt/src/app/plugins/revive-payload.client.ts +++ b/packages/nuxt/src/app/plugins/revive-payload.client.ts @@ -21,7 +21,7 @@ if (componentIslands) { revivers.Island = ({ key, params }: any) => { const nuxtApp = useNuxtApp() if (!nuxtApp.isHydrating) { - nuxtApp.payload.data[key] = nuxtApp.payload.data[key] || $fetch(`/__nuxt_island/${key}`, { + nuxtApp.payload.data[key] = nuxtApp.payload.data[key] || $fetch(`/__nuxt_island/${key}.json`, { responseType: 'json', ...params ? { params } : {} }).then((r) => { diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index bce5e7eb1e..263489b490 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -176,7 +176,7 @@ async function getIslandContext (event: H3Event): Promise { url = await islandPropCache!.getItem(event.path) as string } url = url.substring('/__nuxt_island'.length + 1) || '' - const [componentName, hashId] = url.split('?')[0].split('_') + const [componentName, hashId] = url.split('?')[0].replace(/\.json$/, '').split('_') // TODO: Validate context const context = event.method === 'GET' ? getQuery(event) : await readBody(event) @@ -445,8 +445,8 @@ export default defineRenderHandler(async (event): Promise { describe('component islands', () => { it('renders components with route', async () => { - const result: NuxtIslandResponse = await $fetch('/__nuxt_island/RouteComponent?url=/foo') + const result: NuxtIslandResponse = await $fetch('/__nuxt_island/RouteComponent.json?url=/foo') if (isDev()) { result.head.link = result.head.link.filter(l => !l.href.includes('@nuxt+ui-templates') && (l.href.startsWith('_nuxt/components/islands/') && l.href.includes('_nuxt/components/islands/RouteComponent'))) @@ -1695,7 +1695,7 @@ describe('component islands', () => { }) it('render async component', async () => { - const result: NuxtIslandResponse = await $fetch(withQuery('/__nuxt_island/LongAsyncComponent', { + const result: NuxtIslandResponse = await $fetch(withQuery('/__nuxt_island/LongAsyncComponent.json', { props: JSON.stringify({ count: 3 }) @@ -1716,7 +1716,7 @@ describe('component islands', () => { }) it('render .server async component', async () => { - const result: NuxtIslandResponse = await $fetch(withQuery('/__nuxt_island/AsyncServerComponent', { + const result: NuxtIslandResponse = await $fetch(withQuery('/__nuxt_island/AsyncServerComponent.json', { props: JSON.stringify({ count: 2 }) @@ -1737,7 +1737,7 @@ describe('component islands', () => { }) it('renders pure components', async () => { - const result: NuxtIslandResponse = await $fetch(withQuery('/__nuxt_island/PureComponent', { + const result: NuxtIslandResponse = await $fetch(withQuery('/__nuxt_island/PureComponent.json', { props: JSON.stringify({ bool: false, number: 3487,