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

Add support for suspense when mounting components #359

Merged
merged 2 commits into from
Dec 10, 2024
Merged

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Dec 10, 2024

Description

When defining routes you can define a props function that can be async. By default this does not require suspense to be used. But with this update to the component utils suspense will be used if it is detected.

This makes it possible to use suspense's fallback for loading states.

<Suspense>
  <template #fallback>
    <span>Loading</span>
  </template>

  <RouterView/>
</Suspense>

Copy link

netlify bot commented Dec 10, 2024

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit e97f912
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/6757a10f3c3ba90008bcb491
😎 Deploy Preview https://deploy-preview-359--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pleek91
Copy link
Contributor Author

pleek91 commented Dec 10, 2024

Hmm not sure why the test runner doesn't like Promise.withResolvers. Added ESNext to the tsconfig and it runs locally 🤔

Edit: Updating the node version fixed it.

Comment on lines +38 to +42
// there isn't a way to check if suspense is used in the component without accessing a private property
// @ts-expect-error
if(instance?.suspense) {
return h(suspenseAsyncPropsWrapper(component, values))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stackoverfloweth this is the best way I could figure out to check if the component is within a suspense boundary. This is a private part of the vue api. But if suspense is null that means there's no suspense boundary.

Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👏

@pleek91 pleek91 merged commit ad19ab0 into main Dec 10, 2024
6 checks passed
@pleek91 pleek91 deleted the suspense-support branch December 10, 2024 02:41
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