-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Throw errors returned from incremental chunks when error policy is none
#11032
Conversation
🦋 Changeset detectedLatest commit: 110d982 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -201,10 +201,7 @@ export class InternalQueryReference<TData = unknown> { | |||
return; | |||
} | |||
|
|||
this.result = result; |
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.
It's not clear in this diff, but this.result
is set above in this same function. This removes the unneeded duplication.
size-limit report 📦
|
this.result = result; | ||
this.promise = result.data | ||
? createFulfilledPromise(result) | ||
: createRejectedPromise(result); |
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.
Turns out we never reached this case before! We were throwing the entire result as the error rather than the error
itself, which is a bug. This change in behavior exposed this issue.
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.
If we never reached this before, why do we reach it now?
If I'm not mistaken, you didn't change any code flow above this block - and there should be plenty of cases where result.data
could be undefined
(getCurrentResult
should return undefined
whenever the data
would be {}
).
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.
Perhaps I'm making too much of an assumption with that claim. The reason I feel this way because this was throwing the result
instead of the error
and none of my tests for handling errors caught this. I have tests for all sorts of variations of errors (error on first render, error on refetch, error on incremental chunks of @defer
, etc), so I think either the code block above this happened to catch all of those, or something else was amiss. I think the result.data
just happened to be defined on all cases where it made it past line 195.
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.
FYI, I'll be refactoring this logic anyways in likely my next PR, so expect this stuff to change and work more robustly. I had to get this change in there first to help that refactor.
Sorry for my stupid questions here - it might just be late and I might be missing some obvious things here :) Apart from my questions, which are more about your comments than your code, the code looks fine :) |
Co-authored-by: Lenz Weber-Tronic <[email protected]>
By verbal comment, @phryneas has approved this PR 🙂 |
After some time away I came to realize that the behavior of
errorPolicy: 'none'
when an error is returned in an incremental chunk should be considered incorrect.useSuspenseQuery
throws errors when error policy is none, except for this one case. This made the behavior of this error policy unpredictable.Now all errors are thrown, regardless of whether they are in the first chunk or an incremental chunk when the
errorPolicy
is set tonone
. To get the previous behavior, set theerrorPolicy
toall
, which also has the advantage that it keeps partial data.Checklist: