MCPcopy
hub / github.com/nuxt/nuxt / fetchComponent

Function fetchComponent

packages/nuxt/src/app/components/nuxt-island.ts:230–269  ·  view source on GitHub ↗
(force = false)

Source from the content-addressed store, hash-verified

228 }
229
230 async function fetchComponent (force = false) {
231 nuxtApp[pKey] ||= {}
232 nuxtApp[pKey][uid.value] ||= _fetchComponent(force).finally(() => {
233 delete nuxtApp[pKey]![uid.value]
234 })
235 try {
236 const res: NuxtIslandResponse = await nuxtApp[pKey][uid.value]
237
238 ssrHTML.value = res.html.replaceAll(DATA_ISLAND_UID_RE, `data-island-uid="${uid.value}"`)
239 key.value++
240 error.value = null
241 payloads.slots = res.slots || {}
242 payloads.components = res.components || {}
243
244 if (selectiveClient && import.meta.client) {
245 if (canLoadClientComponent.value && res.components) {
246 await loadComponents(props.source, res.components)
247 }
248 }
249
250 if (res?.head) {
251 if (activeHead) {
252 activeHead.patch(res.head)
253 } else {
254 activeHead = head.push(res.head)
255 }
256 }
257
258 if (import.meta.client) {
259 // must await next tick for Teleport to work correctly with static node re-rendering
260 nextTick(() => {
261 canTeleport = true
262 teleportKey.value++
263 })
264 }
265 } catch (e) {
266 error.value = e
267 emit('error', e)
268 }
269 }
270
271 expose({
272 refresh: () => fetchComponent(true),

Callers 1

setupFunction · 0.85

Calls 3

_fetchComponentFunction · 0.85
loadComponentsFunction · 0.85
emitFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…