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(vue-app): handle promise rejection from asyncData #18585

Merged
merged 6 commits into from Feb 21, 2023
Merged

fix(vue-app): handle promise rejection from asyncData #18585

merged 6 commits into from Feb 21, 2023

Conversation

rchl
Copy link

@rchl rchl commented Jan 27, 2023

When exception is thrown during handling of asyncData, Nuxt catches it and shows server error but it also chains returned promise without using catch. This results in unhandled promise rejection.

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The original code

const promise = promisify(Component.options.asyncData, app.context)
promise.then((asyncDataResult) => {
ssrContext.asyncData[Component.cid] = asyncDataResult
applyAsyncData(Component)
return asyncDataResult
})

gets the asyncData promise and chains it to applyAsyncData. That then doesn't run when asyncData has thrown but since this promise is not further chained (especially to catch) it effectively makes it an unhandled promise rejection error.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Jan 27, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2023

Codecov Report

Base: 66.18% // Head: 66.18% // No change to project coverage πŸ‘

Coverage data is based on head (b970d5f) compared to base (2c6b593).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##              2.x   #18585   +/-   ##
=======================================
  Coverage   66.18%   66.18%           
=======================================
  Files          93       93           
  Lines        4096     4096           
  Branches     1158     1158           
=======================================
  Hits         2711     2711           
  Misses       1119     1119           
  Partials      266      266           
Flag Coverage Ξ”
unittests 66.18% <ΓΈ> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

β˜” View full report at Codecov.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

@danielroe danielroe added the 2.x label Feb 1, 2023
@rchl
Copy link
Author

rchl commented Feb 13, 2023

any prospects for getting this merged?

danielroe
danielroe previously approved these changes Feb 17, 2023
@danielroe danielroe requested a review from pi0 February 17, 2023 11:11
@danielroe danielroe changed the title fix(vue-app): unhandled promise rejection when handling asyncData fix(vue-app): handle promise rejection from asyncData Feb 21, 2023
@danielroe danielroe merged commit 6fa5fc2 into nuxt:2.x Feb 21, 2023
@danielroe danielroe deleted the fix/unhandled-promise branch February 21, 2023 10:04
@danielroe danielroe mentioned this pull request Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants