Error on Suspense + render function + prop change while awaiting for render #7202
-
Hi, I have the following use case:
If during the top level await a prop is changed, then this leads to the following error: Since the same trap works when not using a render function, but directly using the component, it must be related to my code somehow. Any support on how I can solve the problem will be appreciated. The render function is necessary because in my case it contains a bit more logic than in this example. The code for my example is https://stackblitz.com/edit/vitejs-vite-dnzwyk?file=src%2Fuse-render-slow-component.js. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You can use like this: use-render-slow-component.js import { h, ref, unref, onMounted } from 'vue';
import SlowComponent from './SlowComponent.vue';
export function useRenderSlowComponent() {
const data = ref('A');
const Comp = {
setup() {
onMounted(() => {
setTimeout(() => {
data.value = 'B';
}, 700);
});
},
render(props, context) {
return h(
SlowComponent,
{
data: unref(data),
},
null
);
},
};
return {
Comp,
};
} |
Beta Was this translation helpful? Give feedback.
-
this is because the import { h, ref, unref } from 'vue';
import SlowComponent from './SlowComponent.vue';
function defAsyncComponent(
comp,
delay = 0
) {
return {
setup(props, { slots }) {
const p = new Promise(resolve => {
setTimeout(() => {
resolve(() => h(comp, props, slots))
}, delay)
})
return p
}
}
}
export function useRenderSlowComponent() {
const Comp = defAsyncComponent({
props:['state'],
render() {
return h(
SlowComponent,
{
data: this.state,
},
null
)
}
},2000) // this value great than the timeout value in Comp.vue
return {
Comp,
};
} |
Beta Was this translation helpful? Give feedback.
this is because the
Comp
is not an async component. it would help if you wrapped it like the below: