react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Bug]: Error with message of "... call aborted" is thrown instead of standard DOMException

Open faergeek opened this issue 3 years ago • 3 comments

What version of React Router are you using?

6.4.3

Steps to Reproduce

Launch examples/ssr-data-router with npm run dev. Open it in browser and either click Refresh/Stop browser button or press Ctrl/Cmd+R without a pause.

Expected Behavior

AbortSignal.prototype.reason is thrown, which defaults to DOMException with the name 'AbortError' (or whatever you pass to abort method) and it's relatively easy to distinguish from other errors with code like err instanceof DOMException && err.name === 'AbortError' or matching with whatever value the user passes to .abort.

Actual Behavior

Error instance with message "... call aborted" is thrown (can be seen in output of the running server), which needs custom logic matching error message to distinguish it from other errors.

The relevant code throwing that error exists inside submit and loadRouteData.

Replacing both of those lines with throw request.signal.reason; would throw expected error, which is DOMException with 'AbortError' by default or whatever the user passes to .abort call.

If there are no good reasons to keep it as it is, I'm more than happy to submit a PR for that change.

faergeek avatar Nov 23 '22 18:11 faergeek

Yeah I don't see any reason not to do this (pun very much intended) 😉 . Want to push up a PR?

brophdawg11 avatar Dec 07 '22 21:12 brophdawg11

@brophdawg11 great 👍 , I'll push a PR soon

faergeek avatar Dec 08 '22 04:12 faergeek

So, it seems like it won't work because of a polyfill used https://github.com/mysticatea/abort-controller/issues/33

I also tried to not use polyfill by removing "setupFiles" option from jest config (node supports fetch since version 18 without a flag https://nodejs.org/api/globals.html#fetch). But for some reason tests error with "Request is not defined". And that's strange, because if I add console.log(Request) right into a jest.config.js, it's there, but inside tests it's not defined for some reason.

@brophdawg11 do you have any idea on what could be wrong?

faergeek avatar Dec 08 '22 05:12 faergeek

@brophdawg11 Does it make sense to drop polyfill and depend on fetch apis from node 18? Or it's not worth to even try for now?

faergeek avatar Jan 10 '23 04:01 faergeek

Hm - not offhand. My hunch is that there's something also polyfilling down inside @remix-run/web-fetch. Even if we figured out the test/polyfill issue - would we still have to be conditional since reason is not going to be supported everywhere?

if (request.signal.reason instanceof Error) {
  throw request.signal.reason;
} else {
  throw new Error("queryRoute call aborted");
}

brophdawg11 avatar Jan 11 '23 22:01 brophdawg11

Hm, yes. We can only get rid of the polyfill here and use signal.reason if remix/react-router itself would drop support for node < 18, so we're sure that it will work without polyfill. Otherwise it seems that the only way to fix it is to add proper reason support to polyfill. But it looks like polyfill code is not touched over 3 years already, may be it's abandoned. So most probably it would require to maintain a fork for that

faergeek avatar Jan 12 '23 04:01 faergeek

This issue has been automatically marked stale because we haven't received a response from the original author in a while 🙈. This automation helps keep the issue tracker clean from issues that are not actionable. Please reach out if you have more information for us or you think this issue shouldn't be closed! 🙂 If you don't do so within 7 days, this issue will be automatically closed.

github-actions[bot] avatar Apr 17 '23 21:04 github-actions[bot]

This issue has been automatically closed because we didn't hear anything from the original author after the previous notice.

github-actions[bot] avatar Apr 24 '23 21:04 github-actions[bot]

What's the recommended best practice here? Always wrap await router.query(...) with try-catch?

jcoc611-gvt avatar May 01 '23 18:05 jcoc611-gvt

Yes - you should always wrap that in case it throws from being interrupted by another request.

brophdawg11 avatar May 01 '23 18:05 brophdawg11

Is there a resolution for this?

kevin1193 avatar Sep 22 '23 06:09 kevin1193

facing same issue on remix server, any solution for this?

nabeelpkl avatar Oct 12 '23 07:10 nabeelpkl

Actively dealing with this problem. Any updates here?

acolchagoff avatar Nov 03 '23 20:11 acolchagoff

I can take a look at this again now that v2 is node 18+ and polyfills are user-driven

brophdawg11 avatar Nov 06 '23 15:11 brophdawg11

Great to hear! Looking forward on resolving this!

kevin1193 avatar Nov 06 '23 15:11 kevin1193

any updates?

zolzaya avatar Nov 09 '23 01:11 zolzaya

🤖 Hello there,

We just published version 6.22.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

github-actions[bot] avatar Jan 31 '24 15:01 github-actions[bot]

🤖 Hello there,

We just published version 6.22.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

github-actions[bot] avatar Feb 01 '24 20:02 github-actions[bot]