MCPcopy
hub / github.com/nuxt/nuxt / setup

Function setup

packages/nuxt/src/app/components/nuxt-island.ts:81–361  ·  view source on GitHub ↗
(props, { slots, expose, emit })

Source from the content-addressed store, hash-verified

79 },
80 emits: ['error'],
81 async setup (props, { slots, expose, emit }) {
82 let canTeleport = import.meta.server
83 const teleportKey = shallowRef(0)
84 const key = shallowRef(0)
85 const canLoadClientComponent = computed(() => selectiveClient && (props.dangerouslyLoadClientComponents || !props.source))
86 const error = ref<unknown>(null)
87 const config = useRuntimeConfig()
88 const nuxtApp = useNuxtApp()
89 const filteredProps = computed(() => filterIslandProps(props.props))
90 const hashId = computed(() => computeIslandHash(props.name, filteredProps.value, props.context, props.source))
91 const instance = getCurrentInstance()!
92 const event = useRequestEvent()
93
94 let activeHead: ActiveHeadEntry<SerializableHead>
95
96 const eventFetch = import.meta.server ? event!.fetch : globalThis.fetch
97 const mounted = shallowRef(false)
98 onMounted(() => { mounted.value = true; teleportKey.value++ })
99 onBeforeUnmount(() => { if (activeHead) { activeHead.dispose() } })
100 function setPayload (key: string, result: NuxtIslandResponse) {
101 const toRevive: Partial<NuxtIslandResponse> = {}
102 if (result.props) { toRevive.props = result.props }
103 if (result.slots) { toRevive.slots = result.slots }
104 if (result.components) { toRevive.components = result.components }
105 if (result.head) { toRevive.head = result.head }
106 nuxtApp.payload.data[key] = {
107 __nuxt_island: {
108 key,
109 ...(import.meta.server && import.meta.prerender)
110 ? {}
111 : { params: { ...props.context, props: props.props ? JSON.stringify(props.props) : undefined } },
112 result: toRevive,
113 },
114 ...result,
115 }
116 }
117
118 const payloads: Partial<Pick<NuxtIslandResponse, 'slots' | 'components'>> = {}
119
120 if (instance.vnode.el) {
121 const slots = toRaw(nuxtApp.payload.data[`${props.name}_${hashId.value}`])?.slots
122 if (slots) { payloads.slots = slots }
123 if (selectiveClient) {
124 const components = toRaw(nuxtApp.payload.data[`${props.name}_${hashId.value}`])?.components
125 if (components) { payloads.components = components }
126 }
127 }
128
129 const ssrHTML = ref<string>('')
130
131 if (import.meta.client && instance.vnode?.el) {
132 if (import.meta.dev) {
133 let currentEl = instance.vnode.el
134 let startEl: RendererNode | null = null
135 let isFirstElement = true
136
137 while (currentEl) {
138 if (isEndFragment(currentEl)) {

Callers

nothing calls this directly

Calls 15

useRuntimeConfigFunction · 0.90
useNuxtAppFunction · 0.90
filterIslandPropsFunction · 0.90
computeIslandHashFunction · 0.90
useRequestEventFunction · 0.90
isEndFragmentFunction · 0.90
isStartFragmentFunction · 0.90
getFragmentHTMLFunction · 0.90
injectHeadFunction · 0.90
fetchComponentFunction · 0.85
watchFunction · 0.85
loadComponentsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…