When the async component loading time exceeds the timeout, the component will be rendered after the errorComponent
Version
3.1.0-beta.4
Reproduction link
Steps to reproduce
step 1
// App.vue
<template>
<asyncComp message="async comp load complete"></asyncComp>
</template>
<script>
import { defineAsyncComponent, defineComponent, h } from 'vue';
const asyncComp = defineAsyncComponent({
loader: () =>
new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
props: ['message'],
render() {
return h('div', {}, `${this.message}`);
}
});
}, 1000);
}),
loadingComponent: defineComponent({
render: () => h('div', 'loading......')
}),
errorComponent: defineComponent({
render: () => h('div', 'Error load comp')
}),
delay: 0,
timeout: 500,
suspensible: false,
onError(error, retry, fail, attempts) {
console.log(error, attempts);
fail();
}
});
export default {
components: {
asyncComp
}
};
</script>
step 2
// main.js
import { createApp } from 'vue'
import App from './App.vue';
createApp(App).mount('#app');
What is expected?
Error load comp
What is actually happening?
async comp load complete
@edison1105 if it resolved after timeout, it still work, what is the meaning of the timeout?
The above code rendering process is as follows:
<!--start-->
loading......
<!--500ms-->
Error load comp
<!--1000ms-->
async comp load complete
This makes me feel that the timeout just triggers the error display and does not affect the final result
@JasonMgz0411 see this test case: https://github.com/vuejs/vue-next/blob/master/packages/runtime-core/__tests__/apiAsyncComponent.spec.ts#L343
Note you can use onError
for a more advanced usage: https://v3.vuejs.org/api/global-api.html#defineasynccomponent