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
Support interoperability with other version of itself #3071
Comments
cc @KhafraDev wdyt? I think this is needded. |
we've talked about it in the past and there is no good way to support it |
Then we should document it properly. |
Is it not a good way to support it, because it would be too complex or, or because it would eat up a lot of performance? |
Definitely
Neither... well, complexity is also an issue, but it's just that the solution would be sloppy and probably wouldn't work on every version of node we support. For example: what if undici releases a minor version that updates internal state of Request/Response/etc. and is no longer compatible with a node version(s)? It's not impossible to work around, but there is fundamentally no good solution to the problem. It's important to remember that while undici implements fetch, we do not control it when it's used in node. The webidl implementation we have is also meant to be spec compliant, there is no such thing as "RequestInterface" as a possible value of RequestInfo. Why things won't work:
It's totally possible for a third party library to handle the issues themselves, access whatever internal state, and make the two compatible. Take the internal state from one, add whatever is needed (if anything), and assign it to the other. Not a good thing for undici to implement ourselves, but I can see someone else doing it. |
I think adding that script and a |
I think you are right, sadly. The docs should indeed clearly indicate that IMO, the docs should probably recommend to avoid using |
This would solve...
undici is not compatible with other versions of itself, or Node's.
If a library uses
undici
'sfetch()
internally and the user of the library uses Node'sRequest
, or vice versa,fetch()
call will fail with an error like so:This error is misleading as the input is actually a Request that gets casted to string because it comes from another version of
undici
:undici/lib/web/fetch/request.js
Lines 924 to 934 in f51f226
The implementation should look like...
When checking if an input is a request, instead of using
instanceof
, an thorough interface check could be performed.Every fields from the
input
should be checked against the spec's interface https://fetch.spec.whatwg.org/#requestinfoNote that every field of the input Request (including
dispatcher
) should be carried over to the new request.Symbols would probably need to be using a globally namespaced form instead of locally declared symbols (
Symbol.for('undici.XYZ')
) for the initalization process to work here:undici/lib/web/fetch/request.js
Lines 107 to 118 in f51f226
I have also considered...
Additional context
I am trying to make a library to ease the use of
fetch()
by allowing to tranform Requests, and wrap node'sfetch()
. This is not possible if Request/fetch from different sources are mixed togetherThe text was updated successfully, but these errors were encountered: