-
Notifications
You must be signed in to change notification settings - Fork 91
feat(fetchData): no undefined when unmounted #777
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
Conversation
useClientRequests's fetchData no longer returns undefined when the hook is unmounted, instead returns a result object with a descriptive error
|
👷 Deploy request for graphql-hooks-cra pending review. 🔨 Explore the source changes: f2d1947 |
|
@csorfab just let a comment about returning |
|
@csorfab thanks for all the work you've done here. My main concern with this change is that it's a breaking change and because I don't know the motivations that led to the current implementation I wouldn't feel comfortable changing it right now. If you agree with these considerations, can we go back to your first PR and only get the typing change in? |
|
@simoneb Well, the thing is, the other PR would be a major breaking change for Typescript users, for example it would be no longer possible to destructure the result of an awaited fetchData because you can't destructure undefined, and people would have to spam their code with type assertions or optional chaining. This PR is in line with the typing and the way graphql-hooks is intended to be used, and while I obviously don't know the original intent behind the empty resolve(), it definitely feels more like a quick hack, than intended behavior. Calling fetchData after it unmounted is an edge case, and I have a hard time imagining that anyone's code would depend on fetchData returning undefined in that very specific edge case - you always need to check for result.error under normal circumstances, and the original behavior causes bugs with that, that's what happened with me and what motivated this PR. If anything, I think this would fix unnoticed bugs in people's code rather than break anything. All that said, I absolutely understand your concerns, this is definitely not an easy call |
|
@csorfab #96 seems like a quick fix like you mentioned, what Simone meant is that people are currently doing something like the example below would have these changes to break their code current with the introduced changes |
|
@tiagoheliob I understand, but are you sure that people actually do this? Because this behavior is not mentioned anywhere in the docs, nor the typings, and in 99.99% of cases the The only way to find out about this behavior is by looking at the source code after unexpected, hard to reproduce errors (which is how I came about it) |
|
@csorfab good point, I've made some tests and it's working fine, I'll approve it |
tiagoheliob
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thank you all for the cooperation! |
|
Thank you @csorfab for your work and the thought you put into this! This change is now released in the latest version of the package. |
useClientRequests's fetchData no longer returns undefined when the hook is unmounted,
instead returns a result object with a descriptive error
What does this PR do?
It resolves #772 by returning a result object conforming to the typing and normal behavior of useClientRequest's fetchData
Related issues
#772
Checklist