-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(@astrojs/cloudflare): Add support for wasm module imports #8542
Conversation
🦋 Changeset detectedLatest commit: 6a806ef The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
20a0905
to
102f617
Compare
0afaaa1
to
758f9f4
Compare
}, | ||
}); | ||
// | ||
// Sadly, this needs to build esbuild for each depth of routes/entrypoints independently so that relative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas how this could be improved for functionPerRoute mode? The problem is that the esbuild is effectively creating the exact same bundle and duplicating, and now the bundle needs to have relative imports, so the bundles need to be different depending on how deep they are in the tree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO wasm
should be an opt-in functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexanderniebuhr could you explain why, please? I'm curious :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add my 2 cents. It would be nice if this was zero configuration. Its not really "changing" behavior like other configs, rather its adding behavior that the user would expect to work given what works in cloudflare.
That being said, this multiple esbundle depending on depth of the entrypoint is a bit of a hack, and if it stays that way, adding a configuration to opt-in to wasm loading for at least the function per route case makes sense to me.
@alexanderniebuhr were your reservations around this hack or something else?
About the hack, In my development, I wasn't able to specify a different import pattern for the different entrypoints using its onResolve
callback. But it seems like there must be some other better way to do it. I was just hoping that someone might have better insight. Looking deeper at the esbuild plugin documentation, I might be able to do something with the onEnd
callback to modify the imports within each entry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ematipico @adrianlyjak let me explain!
I'm genuinely excited about this feature and would love to see it enabled by default in the long run. 🚀
However, I've got a few thoughts:
- I'm a bit hesitant about the
entryPathsGroupedByDepth
solution. I believe there might be a more efficient approach out there. I'm already thinking about it but need some more time, to fully understand the requirements. - However I don't think it should block this PR - we should iterate on it in a future PR!
- Given that
wasm
isn't a typical use-case for majority of users, my suggestion would be to make this feature opt-in for now. This way, we ensure we don't inadvertently degrade the experience for users withoutwasm
- which we test for, but it still feels a bit hacky. - I also haven't dived deeper into a thorough code review yet. So I don't really know if the current solution is that hacky or fine. I was just going by my initial gut feeling and the comment provided by @adrianlyjak.
- Once we've tested this with real-world use cases & optimized the adapter to reduce code branches (I'm working on that), I would consider making the default
true
, but still leave the flag intact (for user choice).
This mirrors how I usually approach runtime support: opt-in first & switching to default once I'm sure it works for 95% of users.
If we decide to invest the time to find a better solution for the depth issue and include it in this PR, I would love to see it enabled by default. I was just going to suggest: "Ship this first - deal with improvements later."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adrianlyjak I'm keen to assist and offer a fresh perspective. While I haven't fully grasped all the issues yet, I'll delve deeper into your implementation to better understand the challenges you've described. I believe there might be some hooks we can leverage to streamline the process. To reiterate my earlier point, I feel we should merge this PR as it stands and focus on refining it in subsequent iterations.
What are your thoughts, @ematipico?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only further idea to support both would be to use base64 in the vite build always, and then somehow re-interpret an wasm import within the worker esbuild.
I ended up doing this. It seems to work well and not be too complicated. Main complaint is that there's loosely coupled and hard to follow assumptions between the 2 build stages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the long discussion and the technical details that surfaced, I think we should keep the feature opt-in, so we can discuss them offline (discord, github issue, etc.) I want @adrianlyjak 's contribution to be merged ASAP, but we shouldn't rush into "enabled by default".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the feature is opt-in. What's the process for merging? Or do you want further code review? I see this is starting to accumulate conflicts, and I'm hoping to not have to keep up with those. I'll rebase this for the time being (excited about the node compatibility that's conflicting here 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR looks good to me, amazing work! 🚀
In general the process is some more reviews, including one of docs team (maybe uncomment the review request from the PR template.) Once they all approve, merging will be handled by one of the maintainers :)
26d3fbe
to
a925450
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for these docs contributions, @adrianlyjak! I found them super easy to follow and I think they'll be helpful to people using the integration! 🙌
I just had some suggestions for your consideration to adjust them a tiny bit so they would be more in line with how we'd normally write our Astro documentation. See what you think and as I always have to say, I'm just editing for style and structure. It's your job to make the statements true! 😉
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good @adrianlyjak ! Just two tiny suggestions, then we're good to go!
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love to approve great docs! 🥳
Changes
Testing
kill-port
dependency. I attempted to removes skips for flaky startup (I wasn't encountering any flakiness after the port fix locally), however the windows and node 20 environments seem to still consistently fail on 1 or 2 wrangler cli tests. Instead I refactored the skip behavior to be a little simpler to opt-in or out.Docs
Updated README for cloudflare adapter with small section on wasm modules.