Skip to content

Suspense regression when used with RouterView #2143

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

Closed
cexbrayat opened this issue Sep 17, 2020 · 12 comments
Closed

Suspense regression when used with RouterView #2143

cexbrayat opened this issue Sep 17, 2020 · 12 comments

Comments

@cexbrayat
Copy link
Member

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?

@posva
Copy link
Member

posva commented Sep 17, 2020

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

@cexbrayat
Copy link
Member Author

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.

@husayt
Copy link

husayt commented Sep 17, 2020

I have the same issue

@yyx990803
Copy link
Member

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>

@surmon-china
Copy link

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.

@liuweiGL
Copy link

liuweiGL commented Dec 18, 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>

@810505339
Copy link

@810505339
Copy link

为什么 loading 不会出现呢?

@yaquawa
Copy link

yaquawa commented May 9, 2021

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

@obadakhalili
Copy link

@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.

@davidpmccormick
Copy link

davidpmccormick commented Oct 20, 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

@mitow7821
Copy link

[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?

@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests