From 5de7244032cb195ced3d2acd3e4d1df25615c1d0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 20 Mar 2024 00:01:28 +0000 Subject: [PATCH] fix(nuxt): handle underscores in island names (#26370) --- packages/nuxt/src/core/runtime/nitro/renderer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index cde9312494..cfa22ff733 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -205,6 +205,7 @@ const sharedPrerenderCache = import.meta.prerender && process.env.NUXT_SHARED_DA } : null +const ISLAND_SUFFIX_RE = /\.json(\?.*)?$/ async function getIslandContext (event: H3Event): Promise { // TODO: Strict validation for url let url = event.path || '' @@ -212,8 +213,9 @@ async function getIslandContext (event: H3Event): Promise { // rehydrate props from cache so we can rerender island if cache does not have it any more url = await islandPropCache!.getItem(event.path) as string } - url = url.substring('/__nuxt_island'.length + 1) || '' - const [componentName, hashId] = url.split('?')[0].replace(/\.json$/, '').split('_') + const componentParts = url.substring('/__nuxt_island'.length + 1).replace(ISLAND_SUFFIX_RE, '').split('_') + const hashId = componentParts.length > 1 ? componentParts.pop() : undefined + const componentName = componentParts.join('_') // TODO: Validate context const context = event.method === 'GET' ? getQuery(event) : await readBody(event)