-
Notifications
You must be signed in to change notification settings - Fork 24
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
[WIP] use cloudflare native stream take 2 #355
Conversation
[WIP] use cloudflare native stream take 2
Thanks for proposing alt PR. This is also a nice idea to make factory fn and reuse. One different solution would be we change relative imports to I prefer second approach because does not involves increasing internal complexity of unenv and if in future can be used for possible similar situations without making factory for every internal. Also I think would be really worth to investigate Next.js issue closer, if from what I understand one server fn is called from another, it looks really close concept to nitro direct fetch and actually you might want to do something like this. (*) And the change using previous, this or any other method that avoids unenv's stream polyfill, certainly breaks nitro (we don't want that do we? |
We surely do not want to break nitro (or anything, really). |
Using a built-in stream is fine of course but if cloudflare preset / wrangler overrides relative paths of |
Added test via #361 to make sure we don't break it. I think doing this change would only make sense as a last resort (accepting it breaks something else) and using So let's investigate opennext issue first, it is really not a bug here. |
Sorry that I am slow to understand, but what open next issue?
I tried that this morning. I am looking at it as we speak. Thanks for your help and adding the test 🙏 |
(refering to opennextjs/opennextjs-cloudflare#147), if you are investigating it amazing, LMK if could help or wanted me to locally investigate that. |
(mostly thinking out loud and still investigating the OpenNext issue)
I believe that the factory solution in this PR would be work:
while using the alias would not work on cf because importing I'm still investigating a related issue (present wether or not this PR is applied). |
Pooya, I have finally fixed the root cause of the related error I was seeing in OpenNext so that I was able to finally test properly. I can confirm that using the builtin workerd stream implementation fixes the error with Open Next. The way I think about unenv/runtime/node/stream is that it's used for 3 use cases:
What we want is to use the unenv stream polyfill for 1 and 2 but the workerd implementation for 3. For now I can imagine 2 ways to do this:
I believe that the alias solution mentioned before would not work as it would affect all of 1, 2, and 3 - and then break the test you added in workerd. What do you think? |
I think either way, if cloudflare preset is applied and changes
Do you have a reference? What was the issue? (I'm need to understand first how opennext depends on |
I think it will work because fetch uses relative imports but I need to test to make sure. Do you have a reference? What was the issue? For the issue I was chasing:
I hope this helps |
(BTW Thanks for the reference, but where is the direct import of |
Yes it would help to know what using workerd would break.
The PR is about the issue that was preventing me from testing fully. |
Thanks for the ref to opennextjs/src/http that's what was looking for. 👍🏼 It looks like opennextjs reinvented what we did with unenv/nitro for Node HTTP emulation but differently directly in there (and I'm interested in exploring how to unify that). Exposing an internal factory that can be used differently is not an ideal way for me because even if it fixes current opennextjs HTTP compatibility, it means any internal changes to the unenv IncominMessage/ServerResponse can possibly break something and put even more constraints on the future development. My suggestion as follow-up is:
(*) as part, if needed we can even entirely replace current stream polyfill from nstdlib) |
The code in Open Next comes from https://github.com/dougmoscrop/serverless-http
Do you mean that fecth/polyfill would use that while cf would use the native impl?
Would duplicating
Let me know what you think and thanks for the insights ! |
Making I will explain the extent of my concerns (of doing wrapper/dup) in our next call and will try to find some more free time to investigate this story and possibility. |
Ok. What the sake of bundle size, we would prefer using the native implementation but let's discuss of the pros and cons - I'll be out this Thursday, not sure if Igor will join as he's travelling. Do you have some idea for a quick/temp fix for now? |
As for a quick fix, same as my initial comment #355 (comment), using That change will explicitly break our new test as well as nitro as a clear indicator that cloudflare overrides changes Using the wrapper only won't break current If you like to help, adding support for native node stream to current codebase of HTTP polyfill is not that hard thing and while makes little behavior changes in nitro, it is for sake of everyone (reducing bundle / benefit hybrid) and will be consistent between nitro/opennext. |
I tried that (see this comment above) - I had to import from Would that be ok if I submit this in a PR, considering that "That change will explicitly break our new test as well as nitro" - I guess maybe because Nitro is still on 1.x
Yep, I'm willing to help. I only need a few days to move the preset and then I'll be back on this. At that point we should have a VC to discuss a plan/ideas. |
Surely! It is acceptable that we explicitly fail it with alias and as hotfix. As soon as external preset is ready, I plan to migrate current semver-major version of nitro 2.x to unenv v2 (non breaking migration) and we already need to have another override on top of cloudflare preset as there are other issues such as Also there is matter of having a way to opt-out from wrangler build, without it even current |
I can't remember what we said, would |
Yes only we need to automate it so nitro works with unenv v2 out of the box.. |
This could be part of the |
yep |
Closing in favor of #363 as discussed. |
(ref: #352, #353)
@pi0 what about something like this.
It's missing a
http/$cloudflare
that would passReadable
andWritable
fromnode:stream
- and a few more changes.Would that work for you?