2021-10-12 12:51:41 +00:00
|
|
|
<template>
|
2022-01-26 17:24:54 +00:00
|
|
|
<Suspense @resolve="onResolve">
|
2023-11-09 17:01:13 +00:00
|
|
|
<ErrorComponent
|
|
|
|
v-if="error"
|
|
|
|
:error="error"
|
|
|
|
/>
|
|
|
|
<IslandRenderer
|
|
|
|
v-else-if="islandContext"
|
|
|
|
:context="islandContext"
|
|
|
|
/>
|
|
|
|
<component
|
|
|
|
:is="SingleRenderer"
|
|
|
|
v-else-if="SingleRenderer"
|
|
|
|
/>
|
2022-11-09 09:14:15 +00:00
|
|
|
<AppComponent v-else />
|
2021-10-12 12:51:41 +00:00
|
|
|
</Suspense>
|
|
|
|
</template>
|
2021-12-21 14:44:35 +00:00
|
|
|
|
2022-03-18 10:57:53 +00:00
|
|
|
<script setup>
|
2023-01-23 23:37:38 +00:00
|
|
|
import { defineAsyncComponent, onErrorCaptured, onServerPrefetch, provide } from 'vue'
|
2023-10-30 21:05:02 +00:00
|
|
|
import { useNuxtApp } from '../nuxt'
|
|
|
|
import { isNuxtError, showError, useError } from '../composables/error'
|
|
|
|
import { useRoute } from '../composables/router'
|
|
|
|
import { PageRouteSymbol } from '../components/injections'
|
2022-11-09 09:14:15 +00:00
|
|
|
import AppComponent from '#build/app-component.mjs'
|
2023-06-10 09:11:26 +00:00
|
|
|
import ErrorComponent from '#build/error-component.mjs'
|
2022-07-15 22:15:31 +00:00
|
|
|
|
2023-08-07 22:03:40 +00:00
|
|
|
const IslandRenderer = import.meta.server
|
2022-11-24 12:24:14 +00:00
|
|
|
? defineAsyncComponent(() => import('./island-renderer').then(r => r.default || r))
|
|
|
|
: () => null
|
2021-12-21 14:44:35 +00:00
|
|
|
|
2022-03-11 08:22:16 +00:00
|
|
|
const nuxtApp = useNuxtApp()
|
2022-10-08 14:18:57 +00:00
|
|
|
const onResolve = nuxtApp.deferHydration()
|
2022-03-11 08:22:16 +00:00
|
|
|
|
2023-08-07 22:03:40 +00:00
|
|
|
const url = import.meta.server ? nuxtApp.ssrContext.url : window.location.pathname
|
2023-10-30 21:04:45 +00:00
|
|
|
const SingleRenderer = import.meta.test && import.meta.dev && import.meta.server && url.startsWith('/__nuxt_component_test__/') && defineAsyncComponent(() => import('#build/test-component-wrapper.mjs')
|
2023-08-07 22:03:40 +00:00
|
|
|
.then(r => r.default(import.meta.server ? url : window.location.href)))
|
2023-04-06 12:07:22 +00:00
|
|
|
|
2022-08-02 09:58:03 +00:00
|
|
|
// Inject default route (outside of pages) as active route
|
2023-07-05 10:39:39 +00:00
|
|
|
provide(PageRouteSymbol, useRoute())
|
2022-08-02 09:58:03 +00:00
|
|
|
|
2022-03-11 08:22:16 +00:00
|
|
|
// vue:setup hook
|
|
|
|
const results = nuxtApp.hooks.callHookWith(hooks => hooks.map(hook => hook()), 'vue:setup')
|
2023-08-07 22:03:40 +00:00
|
|
|
if (import.meta.dev && results && results.some(i => i && 'then' in i)) {
|
2022-03-11 08:22:16 +00:00
|
|
|
console.error('[nuxt] Error in `vue:setup`. Callbacks must be synchronous.')
|
2021-12-21 14:44:35 +00:00
|
|
|
}
|
2022-03-11 08:22:16 +00:00
|
|
|
|
|
|
|
// error handling
|
|
|
|
const error = useError()
|
|
|
|
onErrorCaptured((err, target, info) => {
|
|
|
|
nuxtApp.hooks.callHook('vue:error', err, target, info).catch(hookError => console.error('[nuxt] Error in `vue:error` hook', hookError))
|
2023-08-07 22:03:40 +00:00
|
|
|
if (import.meta.server || (isNuxtError(err) && (err.fatal || err.unhandled))) {
|
2023-05-03 10:02:07 +00:00
|
|
|
const p = nuxtApp.runWithContext(() => showError(err))
|
2023-01-23 11:13:21 +00:00
|
|
|
onServerPrefetch(() => p)
|
2023-03-31 09:17:10 +00:00
|
|
|
return false // suppress error from breaking render
|
2022-03-11 08:22:16 +00:00
|
|
|
}
|
|
|
|
})
|
2022-11-24 12:24:14 +00:00
|
|
|
|
|
|
|
// Component islands context
|
2023-08-07 22:03:40 +00:00
|
|
|
const islandContext = import.meta.server && nuxtApp.ssrContext.islandContext
|
2021-12-21 14:44:35 +00:00
|
|
|
</script>
|