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

fix: useAsync bug with Promises #210

Closed
nvitaterna opened this issue Aug 18, 2020 · 0 comments · Fixed by #211
Closed

fix: useAsync bug with Promises #210

nvitaterna opened this issue Aug 18, 2020 · 0 comments · Fixed by #211
Assignees
Labels
bug Something isn't working

Comments

@nvitaterna
Copy link
Contributor

🐛 The bug
UseAsync checks for x instanceof Promise which isn't completely reliable. Should probably check for .then instead to cover other Promise libraries. This makes Nuxt not fetch the data.

🛠️ To reproduce
For example, using the Nuxt Content Module:

// doesn't work
const article = useAsync(() =>
  $content('articles', params.value.slug).fetch<ArticleResult>()
);

//works
const article = useAsync(() =>
  Promise.resolve(
    $content('articles', params.value.slug).fetch<ArticleResult>()
  )
);

This is because, for whatever reason, the .fetch() function from the content module does not return an instanceof Promise.

🌈 Expected behaviour
Expect it to fetch the data on the server.

@nvitaterna nvitaterna added the bug Something isn't working label Aug 18, 2020
@nvitaterna nvitaterna changed the title fix: fix: useAsync bug with Promises Aug 18, 2020
danielroe pushed a commit that referenced this issue Aug 18, 2020
Co-authored-by: Nicolas Vitaterna <nvitaterna@gmail.com>

closes #210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants