-
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
Set immediate error callbacks #1348
Set immediate error callbacks #1348
Conversation
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.
Could we just use setTimeout
instead of setImmediate
? I’m going to look at the tests now and see why they are complaining.
src/core/QueryManager.ts
Outdated
console.error(`Error in observer.error \n${e.stack}`); | ||
} | ||
// defer to avoid potential errors propagating back to Apollo | ||
(setImmediate || setTimeout)(() => observer.error(apolloError)); |
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.
Could we just use setTimeout(() => { ... }, 0)
here? Is there any advantage to using setImmediate
?
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.
setImmediate
was called out explicitly in this comment, not sure if there's a real advantage, or if it's enough to offset the loss in readability. I can drop it!
src/core/QueryManager.ts
Outdated
@@ -438,11 +435,10 @@ export class QueryManager { | |||
|
|||
if (isDifferentResult) { | |||
lastResult = resultFromStore; | |||
try { | |||
// defer to avoid potential errors propagating back to Apollo | |||
(setImmediate || setTimeout)(() => { |
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.
Same here.
It looks like TypeScript is failing in CI and not the actual tests. Could you try changing the export interface Observer<T> {
readonly next?: (value: T) => void;
readonly error?: (error: Error) => void;
readonly complete?: () => void;
} I think I recall |
@calebmer tried applying your TS type fix but you still receive TS errors |
…diate-error-callbacks # Conflicts: # src/core/QueryManager.ts
Went ahead and fixed the type errors. Now we're getting into the weird test stuff. I might be able to figure out how to fix some of them. |
@abhiaiyer91 the current commit should fix the errors 😊 |
For the It was calling it three times before the changes in this PR, but the third call was made after the assertion, so the test passed. Now the timing has changed subtly. I have no idea what the desired behavior is here... it's possible there was already a bug here that the tests didn't catch until now. |
Similarly, the I wonder if it would be a less impactful solution to do something like this...
It's a lot harder to read and understand what's going on, but it would probably break fewer tests. (And I have to wonder if other libraries and apps that depend on apollo-client depend on this sort of timing in subtle ways) |
I doubt this change actually breaks real apps. It’s unfortunate that it breaks a lot of tests 😣 |
# Conflicts: # src/core/QueryManager.ts
Yeah, had a much easier time with that approach: #1367. Let me know if I should close this one if you'd rather go with this approach and somehow fix all the tests. |
Yeah, #1367 looks really nice. I don’t think there is any real substantial difference between the two approaches. Since the tests are green let’s pursue that one 👍 |
This is an attempt to fix #1141 . Unfortunately I had a lot of trouble testing this - it's just hard to coerce Mocha to allow uncaught exceptions.