Skip to content

BUGFIX: Fix handleReject #47

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

Merged
merged 2 commits into from
May 13, 2019
Merged

BUGFIX: Fix handleReject #47

merged 2 commits into from
May 13, 2019

Conversation

kentcdodds
Copy link

Description

By simply returning the error it changed the promise chain from rejected to resolved which was causing me issues.

Breaking changes

Does this include any (potentially) breaking API changes?

Only if people were relying on the bug.

Checklist

Make sure you check all the boxes. You can omit items that are not applicable.

  • Implementation for both <Async> and useAsync()
  • Added / updated the unit tests
  • Added / updated the documentation N/A
  • Updated the PropTypes N/A
  • Updated the TypeScript type definitions N/A

Kent C. Dodds added 2 commits May 13, 2019 02:35
By simply returning the error it changed the promise chain from rejected to resolved which was causing me issues.
@kentcdodds
Copy link
Author

Sorry, I don't know what busted or have time ATM to fix it 😬

If you have a second to get this fix released (even if you treat this as a bug report rather than a PR and push the fix yourself that's fine) that would be wonderful.

@ghengeveld
Copy link
Member

Thanks for your feedback and trying to provide a fix along with it! This was originally done explicitly for compatibility with React Final Form (which expects a resolved promise).

I'm on board with the change, as I don't want to break the Promise contract by not re-throwing. I do want to tread carefully when dealing with a breaking API change like this, so it won't be a quick fix. There's tests failing that I need to fix. Also the Async component API needs to be changed in tandem.

@kentcdodds
Copy link
Author

Understood. I'll publish a temporary fork for my workshop then. Thanks for getting back to me so quickly!

Pretty weird that Final Form expects a resolved promise. Should be easy for people who are using that lib to change it from rejected to resolved themselves 👍

@ghengeveld ghengeveld changed the base branch from master to run-promise-reject May 13, 2019 09:31
@ghengeveld ghengeveld merged commit a4c7a4c into async-library:run-promise-reject May 13, 2019
@kentcdodds kentcdodds deleted the patch-2 branch May 13, 2019 09:32
@ghengeveld
Copy link
Member

Merged it to a separate branch. Will handle it from here 👍
It's going to be a major release as it's a breaking API change.

@kentcdodds
Copy link
Author

kentcdodds commented May 13, 2019

Hey @ghengeveld, actually if you could do me another huge favor I would be super appreciative.

Could you publish this change as a beta release? For my workshop, I'd much rather have people import {useAsync} from 'react-async' than import {useAsync} from '@kentcdodds/react-async-6.2.1-temp-fix@6.2.1' 😅

Even if the dist tag is something weird, that'd just make things nicer for me and the attendees if that's ok :)

@ghengeveld
Copy link
Member

Sure, I'll get you a pre-release shortly.

@kentcdodds
Copy link
Author

You're the best! Thanks!

@ghengeveld
Copy link
Member

Actually this involves a bit more work, as re-throwing will cause an uncaught promise rejection in the Fulfilled component.

Anyway, you can install react-async@kcd for now. It's got some tests skipped and you probably can't use <Fulfilled>.

@kentcdodds
Copy link
Author

Ok, sounds good. Thank you so much for giving me some of your time today @ghengeveld! And I love react-async 💯

@ghengeveld
Copy link
Member

ghengeveld commented May 13, 2019 via email

@Tomino2112
Copy link

Hi, can I help somehow to get this over the line?

@ghengeveld
Copy link
Member

ghengeveld commented Jul 2, 2019

@Tomino2112 Yeah, please do! Here's what has to happen:

  • Revert the change that propagates the rejection, because it breaks the Fulfilled component. Or even better, start fresh from the master branch.
  • Expose a new promise property from useAsync and in the render props of <Async>, which rejects or resolves along with the internal promise. I would just create a new Promise(...) along with new window.AbortController() and keep it as a ref. It can be resolved/rejected from handleResolve and handleReject.
  • The new prop must be tested and documented.

@ghengeveld
Copy link
Member

@all-contributors please add @kentcdodds for code

@allcontributors
Copy link
Contributor

@ghengeveld

I've put up a pull request to add @kentcdodds! 🎉

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.

3 participants