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

Allow nested Suspense components to interact #5637

Closed
cabal95 opened this issue Mar 28, 2022 · 2 comments
Closed

Allow nested Suspense components to interact #5637

cabal95 opened this issue Mar 28, 2022 · 2 comments
Labels

Comments

@cabal95
Copy link

cabal95 commented Mar 28, 2022

What problem does this feature solve?

We have some components that wrap their inner content in a Suspense component to provide a better UI. When these components are placed on an Edit page this works great. Meaning, user clicks Edit and the new "edit UI" is shown with a spinner in the one section that is being loaded asynchronously.

However, at other times these components are used in the "view UI", that is on initial page load. In those cases we want to delay showing the entire page until everything is ready. To do that, we put a Suspense component at the top of the DOM that contains the entire page. So we end up with something akin to:

<Suspense>
  <h1>Page Header</h1>
  <div>other content and components</div>
  <CustomComponent>
    <Suspense>
      ...
    </Suspense>
  </CustomComponent>
</Suspense>

The problem is that is seems Suspense events do not cross Suspense Boundaries. Meaning, the Suspense component inside CustomComponent seems to swallow the pending/resolved events so they do not propagate up to the root Suspense component. We would love an option to be added to Suspense that allows it to propagate those events to the parent boundary so that the top-level Suspense can keep the content hidden until all descendant components are fully loaded.

We have considered building our own custom Suspense component, and we could likely achieve most functionality for this via defineAsyncComponent (or rather, an overload of it). But we don't see any way to capture async setup() without getting into the internals of Vue.

If this is not a feature that would be up for considering, we can pursue the custom component, but since it wouldn't give us all the features we want it wouldn't be ideal.

What does the proposed API look like?

I think it would make sense for the parent Suspense component to be in charge of deciding if it waits for descendant Suspense components as well. So something like:

<Suspense :includeDescendantBoundaries="true">
  <h1>Page Header</h1>
  <div>other content and components</div>
  <CustomComponent>
    <Suspense>
      ...
    </Suspense>
  </CustomComponent>
</Suspense>
@ferferga
Copy link

ferferga commented Apr 4, 2024

@sodatea I think this issue can be closed now? Isn't this what suspensible already does? See #6736

There's no mention about it in the docs though, maybe I'll open a PR there.

@sodatea
Copy link
Member

sodatea commented Apr 8, 2024

Yeah, you are right. Thanks for the reminder!

@sodatea sodatea closed this as completed Apr 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants