apollo-client: useLazyQuery Uncaught (in promise)DOMException: signal is aborted without reason
Uncaught (in promise)DOMException: signal is aborted without reason
these below code maybe cause the exception,can we catch the exception?
abortControllersRef.current.forEach((controller) => {
controller.abort();
});
asyncUpdate(signal: AbortSignal) {
return new Promise<QueryResult<TData, TVariables>>((resolve, reject) => {
const watchQueryOptions = this.watchQueryOptions;
const handleAborted = () => {
this.asyncResolveFns.delete(resolve)
this.optionsToIgnoreOnce.delete(watchQueryOptions);
signal.removeEventListener('abort', handleAborted)
reject(signal.reason);
};
this.asyncResolveFns.add(resolve);
this.optionsToIgnoreOnce.add(watchQueryOptions);
signal.addEventListener('abort', handleAborted)
this.forceUpdate();
});
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (6 by maintainers)
I’m also having an issue here, and don’t fully understand how this is marked resolved.
In my tests, using
@apollo/client
3.7.9
, and React18.0.0
, I get anUncaught (in promise)DOMException: signal is aborted without reason
error pretty much any time I useuseLazyQuery
in a component.This seems to be because of React v18’s
reactStrictMode
, which causes components in dev mode to always unmount and re-render. See: https://github.com/vercel/next.js/issues/35822So I don’t see how there’s anyway to use
useLazyQuery
andreactStrictMode: true
together, without triggering this error all the time ?I’m not sure, seems to happen all the time with latest React v18 and
reactStrictMode: true
Surely we don’t want to wrap everything in
try/catch
and check forerror.name === 'AbortError'
every time we useuseLazyQuery
? It seems odd.I know I could probably create my own version of
useLazyQuery
which by default ignores these errors (like @jerelmiller suggested here https://github.com/apollographql/apollo-client/pull/10427#issuecomment-1419679013)So I’ll either do that, or downgraded to
3.7.3
, as I don’t want to disablereactStrictMode
.But just trying to understand whether this really is intended behaviour or not for React 18 and
reactStrictMode: true
Hello,
I have also the same issue after upgrading the
@apollo/client
library from version3.7.1
to3.7.8
when usinguseLazyQuery
(probably the same withuseQuery
?).The bug was introduced with version
3.7.4
.Here is the stack trace for reference:
@jerelmiller you have merged PR #10427 but it doesn’t seem to fix the issue (if it’s the same).
@70nyIT I’ve kept this closed because I’m going to track this in #10533 which is a pretty compelling case to change the behavior. I’d recommend following that issue to keep track of updates.
@guicara As mentioned in https://github.com/apollographql/apollo-client/issues/10520#issuecomment-1470354115, I’m planning on changing the behavior. We’ve got this issue queued up for us to look at, so it will get some attention in the near term.
Hey all 👋
We just released v3.7.11 that contains a change to the behavior of
useLazyQuery
that will now allow the promise to resolve naturally rather than rejecting with an abort error when a component unmounts. I hope this works better for you!Confirmed working as expected! Thanks @jerelmiller
I’ve changed my mind. I’m going to reopen this issue so that I can tag it in my PR. This will close again when the PR is merged.
I agree with @guicara . This is why I was asking the reason for this issue being market as “Closed”
For me, it’s a bug AND a breaking change. A minor version upgrade should not cause something as important!
@jerelmiller in our project we use
useLazyQuery
most of the time. it allows us to control when to trigger the query or mutation. In the following example, we have a custom hook to fetch some data. ThefetchUsers
method is then called in auseEffect
hook, or when a user clicks on a button (for example).