Subscribe on changes!

`errorCaptured` not triggered by error in `async setup` during SSR

avatar
Dec 5th 2020

Version

3.0.4

Reproduction link

https://codesandbox.io/s/ssr-async-setup-error-4tfiq?file=/src/index.js:0-1145

Steps to reproduce

const { createSSRApp, defineComponent } = require('vue')
const { renderToString } = require('@vue/server-renderer')

const children = defineComponent({
  name: 'child1',
  setup() {
    // some error...
    throw new Error('child1 error!')
  },
  template: `<div class="children">{{ test }}</div>`
})

const asyncChildren = defineComponent({
  name: 'asyncChildren',
  async setup() {
    // some async error...
    // e.g. axios.fetch...
    // throw new Error('async child error!')
    return Promise.reject('async child error!')
  },
  template: `<div class="async-children">{{ test.abc }}</div>`
})

const app = createSSRApp({
  name: 'App',
  components: {
    children,
    asyncChildren
  },
  template:
  `
    <div class="app">
      <suspense>
        <children />
        <async-children />
      </suspense>
    </div>
  `,
  errorCaptured(error) {
    console.log('-----errorCaptured', error)
  }
})

app.config.errorHandler = (error) => {
  console.log('-----errorHandler', error)
}

renderToString(app).then(res => {
  console.log('----renderToString', res)
}).catch(error => {
  console.log('----renderToString error', error)
})

What is expected?

async setup function can throw async error to parent.

What is actually happening?

no handle async error.


onErrorCaptured hook and errorHandler can capture the async error, but not capture the async setup function async error.

In the package server-renderer, there is also no error handling for serverPrefetch and async setup

avatar
Dec 7th 2020

@yyx990803

avatar
Dec 24th 2020

@posva I am working on this, should we also handle error in renderToString function ?

avatar
Dec 24th 2020

I'm actually not sure. The best is to make it consistent with Vue 2