XMLHttpRequest: Support synchronous requests
- See https://github.com/mswjs/interceptors/pull/108
Need to explore and verify whether we support synchronous XHR requests. I think we should support them in Node as-is, but not sure how it applies to the browser behavior. There's already a (failing) test committed by a contributor, that's a good starting point.
Since we're using Proxies since #337, I'd expect targeting sync requests shouldn't be a problem.
We should be able to support this in Node.js but this won't work in the browser where MSW uses a Service Worker. Synchronous XHR requests do not trigger the "fetch" event of the worker and there's nothing we can do to circumvent that. I wouldn't split a single interception unit (XHR) to cover different behaviors of that request class. That's unreliable and will be extremely hard to maintain, not to mention the amount of architectural changes required to make this happen, in the first place.
Hello. In the current solution, your interceptors break client applications that use synchronous requests. First, we need to make sure that when we try to make a synchronous request, control is transferred to the original XMLHttpRequest instead of the proxy.
@avivasyuta, sounds like a good plan. I think starting with a test for this also makes a good first step. Would you have the chance to submit a pull request so we fix this for everyone?
Sure. I'll try to fix it.
I would also like to ask you to take a look at this PR. It's been hanging for 2 weeks now and you don't seem to be getting notifications.
@avivasyuta, I've seen the pull request, I simply didn't have time to get to it yet. I approach open source to the best availability of my time, and sometimes things may take weeks or even months to get a proper review. Since I do this as a hobby in my free time, I hope for your understanding when it comes to timing.
Released: v0.34.3 🎉
This has been released in v0.34.3!
Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.