feat(nuxt): emit error in ssr-error event (#21547)

This commit is contained in:
Rodrigo Pimentel 2023-06-14 19:44:43 +01:00 committed by GitHub
parent 187230b0c5
commit b37ec72f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,15 +29,19 @@ const NuxtClientFallbackServer = defineComponent({
default: () => false default: () => false
} }
}, },
emits: ['ssr-error'], emits: {
'ssr-error' (_error: unknown) {
return true
}
},
setup (props, ctx) { setup (props, ctx) {
const vm = getCurrentInstance() const vm = getCurrentInstance()
const ssrFailed = ref(false) const ssrFailed = ref(false)
onErrorCaptured(() => { onErrorCaptured((err) => {
useState(`${props.uid}`, () => true) useState(`${props.uid}`, () => true)
ssrFailed.value = true ssrFailed.value = true
ctx.emit('ssr-error') ctx.emit('ssr-error', err)
return false return false
}) })
@ -50,10 +54,10 @@ const NuxtClientFallbackServer = defineComponent({
} }
return { ssrFailed, ssrVNodes } return { ssrFailed, ssrVNodes }
} catch { } catch (ssrError) {
// catch in dev // catch in dev
useState(`${props.uid}`, () => true) useState(`${props.uid}`, () => true)
ctx.emit('ssr-error') ctx.emit('ssr-error', ssrError)
return { ssrFailed: true, ssrVNodes: [] } return { ssrFailed: true, ssrVNodes: [] }
} }
}, },