Subscribe on changes!

Suspense regression when used with RouterView

avatar
Sep 17th 2020

Version

3.0.0-rc.12

Reproduction link

https://jsfiddle.net/vmprxysu/

Steps to reproduce

Consider a component like the following:

<Suspense>
  <template #fallback>Loading...</template>
  <router-view />
</Suspense>

with a router config loading an async component

What is expected?

In rc.10, we see the loading indicator and then the async component is displayed

What is actually happening?

In rc.12 nothing is displayed. Is this expected with the recent changes or is it a regression?

avatar
Sep 17th 2020

Probably related to the rendered component being nested. The component is displayed if the v-slot api is used

avatar
Sep 17th 2020

You mean if we use <hello /> directly instead of <router-view />? If so, yes it does work. But as it was nice to be able to use Suspense around the RouterView to handle the async loading, I thought it was worth opening an issue.

avatar
Sep 17th 2020

I have the same issue

avatar
Sep 18th 2020

Similar to <transition>, the new Suspense now must be used with <router-view> via its slot-based syntax because it now must have direct access to the toggled root node:

<router-view v-slot="{ Component }">
  <suspense>
    <component :is="Component"/>
  </suspense>
</router-view>
avatar
Sep 24th 2020

Similar to <transition>, the new Suspense now must be used with <router-view> via its slot-based syntax because it now must have direct access to the toggled root node:

<router-view v-slot="{ Component }">
  <suspense>
    <component :is="Component"/>
  </suspense>
</router-view>

[Vue warn]: <Suspense> slots expect a single root node.

avatar
Dec 18th 2020

Similar to <transition>, the new Suspense now must be used with <router-view> via its slot-based syntax because it now must have direct access to the toggled root node:

<router-view v-slot="{ Component }">
  <suspense>
    <component :is="Component"/>
  </suspense>
</router-view>

[Vue warn]: <Suspense> slots expect a single root node.

Fixed:

  <router-view v-slot="{ Component }">
    <suspense>
      <div>
        <component :is="Component" />
      </div>
    </suspense>
  </router-view>
avatar
Apr 28th 2021

为什么 loading 不会出现呢?

avatar
May 9th 2021

Now it shows the <router-view /> but not showing the <template #fallback>, is this is the intended behavior?

avatar
Jul 28th 2021

@yaquawa

Now it shows the <router-view /> but not showing the <template #fallback>, is this is the intended behavior?

https://v3.vuejs.org/guide/migration/suspense.html#:~:text=Vue%20Router%20has,the%20usual%20way.

avatar
Oct 20th 2021

The slot-based-syntax example in the router docs referenced by @yyx990803 above shows a #default and a #fallback template, but like @yaquawa, I don't see anything rendered in the #fallback under conditions where I would expect to.

Edit: found that adding timeout=0 solves it, as mentioned here

avatar
Feb 16th 2022

[Vue warn]: <Suspense> slots expect a single root node.

Fixed:

  <router-view v-slot="{ Component }">
    <suspense>
      <div>
        <component :is="Component" />
      </div>
    </suspense>
  </router-view>

I've added keep-alive and it's not working because of this extra div. Is there any way to disable that warning without adding div?