Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
fix: use Promise.resolve() to cover all possible promise cases (#211)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Vitaterna <nvitaterna@gmail.com>

closes #210
  • Loading branch information
nvitaterna authored Aug 18, 2020
1 parent 4764d1c commit 6d10312
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@ export const useAsync = <T>(
process.client &&
window[globalNuxt]?.context.isHMR)
) {
const p = cb()

if (p instanceof Promise) {
if (process.server) {
onServerPrefetch(async () => {
_ref.value = await p
})
} else {
// eslint-disable-next-line
p.then(res => (_ref.value = res))
}
const p = Promise.resolve(cb())

if (process.server) {
onServerPrefetch(async () => {
_ref.value = await p
})
} else {
_ref.value = p
// eslint-disable-next-line
p.then(res => (_ref.value = res))
}
}

Expand Down

1 comment on commit 6d10312

@vercel
Copy link

@vercel vercel bot commented on 6d10312 Aug 18, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.