-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Suspense doesn't display fallback content and warning is output #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
<router-view v-slot="{ Component }">
<Suspense>
<template>
<template #default>
<component :is="Component" />
</template>
<template #fallback>
<span>Loading...</span>
</template>
</template>
</Suspense>
</router-view> Maybe you should do it like this. |
Not working. |
const Comp = defineComponent({
render() {
return h(
'div',
{
class: 'child'
},
this.$slots.default({ Component: hello })
)
}
}) I tried to use |
/cc @posva |
I also tried the case without using router-view and was able to confirm that the fallback content is displayed. |
I'll transfer this to the vue-router repo |
@seijikohara You may need to add a timeout on your suspense declaration (since changes in Vue 3.0.0-rc.12, see the discussion in vuejs/core#2142). Something like The warning is indeed painful, and is an issue in vue-next @LinusBorg |
I added |
this works well for me after many tries <RouterView name="default" v-slot="{ Component, route }">
<transition :name="route.meta.transition" mode="out-in" :duration="300" :key="route.path">
<Suspense >
<template #default>
<component :is="Component" :key="route.path"/>
</template>
<template #fallback>
<div>
Loading...
</div>
</template>
</Suspense>
</transition>
</RouterView> Although it re-mounts with every route request. any cleaner ideas! |
I could fixed the problem by implementing
And in the
And it works like charm ✨ The only drawback of this solution is that you get the following warning message prompted in the console:
Does someone know how to prevent this warning message from being prompted? Thanks 🙂 |
The best way to use RouterView, Suspense, Transition and KeepAlive together is as mentioned on the Vue Docs site under the Suspense Component page |
You can get away with no warning by:
|
I fixed this issue with the wrapping of the <router-view v-slot="{ Component }">
<suspense timeout="0">
<div>
<component :is="Component"></component>
</div>
<template #fallback>
<div>
Loading...
</div>
</template>
</suspense>
</router-view> |
<RouterView v-slot="{ Component }">
<template v-if="Component">
<Transition mode="out-in">
<KeepAlive>
<Suspense>
<!-- 主要内容 -->
<component :is="Component"></component>
<!-- 加载中状态 -->
<template #fallback>
正在加载...
</template>
</Suspense>
</KeepAlive>
</Transition>
</template>
</RouterView> Add this works for me. <template v-if="Component">
...
</template> |
|
When Solution 1: Use v-if to ensure rendering only when Component exists<router-view v-slot="{ Component }">
<template v-if="Component">
<Suspense>
<component :is="Component" />
<template #fallback>
<div>Loading...</div>
</template>
</Suspense>
</template>
</router-view> Solution 2: Add a wrapper element for the component<router-view v-slot="{ Component }">
<Suspense>
<div> <!-- Add wrapper element -->
<component :is="Component" />
</div>
<template #fallback>
<div>Loading...</div>
</template>
</Suspense>
</router-view> |
Using this approach does not trigger navigation guards in component, like we were using |
Version
3.0.2
Reproduction link
https://jsfiddle.net/seijikohara/jmw3rpue/
Steps to reproduce
No fallback content is displayed and warning is output.
The version of Vue is 3.0.2.
[Vue warn]: <Suspense> slots expect a single root node.
What is expected?
Show fallback contents until the component of
async setup
is initialized.What is actually happening?
No fallback content is displayed and warning is output.
The text was updated successfully, but these errors were encountered: