Skip to content

Commit

Permalink
fix(nuxt): handle underscores in island names (#26370)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 20, 2024
1 parent 0001808 commit 5de7244
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,17 @@ const sharedPrerenderCache = import.meta.prerender && process.env.NUXT_SHARED_DA
}
: null

const ISLAND_SUFFIX_RE = /\.json(\?.*)?$/
async function getIslandContext (event: H3Event): Promise<NuxtIslandContext> {
// TODO: Strict validation for url
let url = event.path || ''
if (import.meta.prerender && event.path && await islandPropCache!.hasItem(event.path)) {
// 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)
Expand Down

0 comments on commit 5de7244

Please sign in to comment.