Skip to content
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

Update Suspense usage #2099

Merged
merged 14 commits into from
Sep 15, 2020
Merged

Update Suspense usage #2099

merged 14 commits into from
Sep 15, 2020

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Sep 11, 2020

Main changes:

  • <Suspense> now expects a single root node (cannot be fragment) for the default/fallback slots.

  • An already-resolved suspense only enters "pending state" when the default slot's root node changes.

  • By default, the current active tree will stay on the screen until the pending tree is resolved. The pending tree, when resolved, replaces the previous active tree and becomes the new active tree.

  • A timeout prop can be specified - if a pending tree remains pending past the timeout threshold, the active tree will be unmounted and be replaced by the fallback tree.

  • New nested async child rendered inside an already resolved suspense no longer puts the suspense into pending state (TODO: components with async setup() should be allowed to declare its own loading state / timeout etc. just like defineAsyncComponent)

  • @recede event has been replaced by @pending and now fires right when a new pending tree is being processed (instead of after the fallback tree is mounted)

  • <Suspense> can now be used with <transition> and <keep-alive>:

    <transition mode="out-in">
      <keep-alive>
        <suspense>
          <component :is="view"/>
          <template #fallback>
             loading...
          </template>
        </suspense>
      </keep-alive>
    </transition>

@CyberAP
Copy link
Contributor

CyberAP commented Sep 11, 2020

now expects a single root node (cannot be fragment) for the default/fallback slots.

Can it be used with components wrapped with renderless components?

<!-- Renderless.vue -->
<template>
  <slot />
</template>
<Suspense>
  <Renderless>
    <div />
  </Renderless>
</Suspense>

@CyberAP
Copy link
Contributor

CyberAP commented Sep 11, 2020

A timeout prop can be specified - if a pending tree remains pending past the timeout threshold, the active tree will be unmounted and be replaced by the fallback tree.

Would it be possible to add a new Composition hook for the cleanup?

import { onTimeout } from 'vue'

export default {
  setup() {
    const { promise, cancel } = asyncRequest()    

    onTimeout(() => { cancel() })

    return promise // will throw on timeout, but that's already handled by Suspense
  }
}

@yyx990803
Copy link
Member Author

@CyberAP renderless component will work without transition.

@yyx990803 yyx990803 marked this pull request as ready for review September 14, 2020 14:46
@yyx990803 yyx990803 merged commit 5ae7380 into master Sep 15, 2020
@yyx990803 yyx990803 deleted the new-suspense branch September 15, 2020 16:45
cexbrayat added a commit to cexbrayat/vue-test-utils-next that referenced this pull request Sep 16, 2020
vuejs/core#2099 introduced a big refactoring in how Suspense works, which broke VTU.
`SuspenseBoundary` no longer exposes the same interface, so our current implementation was not compiling anymore (and throwing at runtime).
This solves the issue and simplifies the current code, as the newly introduced `activeBranch` field now contains the... active branch of the Suspense, so we just have to check that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants