kit
kit copied to clipboard
feat: add support for read in edge environments
This PR helps with the cloudflare part of #12446. Added a test case and I also tested in a project bootstrapped with create cloudflare@latest. Hope i didn't miss anything 🤞.
Thanks all.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.
Tests
- [x] Run the tests with
pnpm testand lint the project withpnpm lintandpnpm check
Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.
Edits
- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.
🦋 Changeset detected
Latest commit: 3f0328eb2f323a3d8fde9e1ff7666bd622284ccc
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 4 packages
| Name | Type |
|---|---|
| @sveltejs/adapter-netlify | Minor |
| @sveltejs/adapter-vercel | Minor |
| @sveltejs/adapter-cloudflare | Minor |
| @sveltejs/kit | Minor |
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
Preview: https://svelte-dev-git-preview-kit-13859-svelte.vercel.app/
Not sure why that particular firefox CI test failed but it did pass on my local machine (pnpm test:cross-platform:build). Let me know, thanks!
Thanks for this PR! Is there any chance you could continue the work from https://github.com/sveltejs/kit/pull/11674 so that it's implemented in the Netlify and Vercel adapters too? I think if the reusable fetchFile function could allow passing a fetch function to it, we could pass env.ASSETS.fetch in the case of the Cloudflare adapter and it would just work.
Not sure why that particular firefox CI test failed but it did pass on my local machine (
pnpm test:cross-platform:build). Let me know, thanks!
I re-ran the test in CI and it passes. Probably just a flaky test that failed.
Ah yes. Sorry I missed Rich's PR in my search. Will look into it. Thanks for the input!
@eltigerchino extracted into a streamFileContent function via https://github.com/sveltejs/kit/pull/13859/commits/6da55ed8bffa335290281405b2fa79cf61aa5bcd. A couple of things:
- added some unit tests; I don't think they are strictly necessary but nice to have anyway,
- exported this util via
@sveltejs/kit/adapter, as I thinkkitis already a peer-dependency for all adapters anyway, - settled with this name rather than
fetchFilesince I feel likefetchwould indicate a returnedResponse.
Also, I haven't added read for netlify & vercel yet, since edge environment can't be easily tested locally for them as far as I know (vercel requires connecting to a cloud project, and netlify docs says edge functions don't work locally).
I can spawn up some projects in netlify & vercel and do some manual tests, but I feel like i shouldn't block progress here. How about I do that in a separate PR?
Thanks
Thank you!
Also, I haven't added
readfor netlify & vercel yet, since edge environment can't be easily tested locally for them as far as I know (vercel requires connecting to a cloud project, and netlify docs says edge functions don't work locally).I can spawn up some projects in netlify & vercel and do some manual tests, but I feel like i shouldn't block progress here. How about I do that in a separate PR?
Yeah, manual testing for those are fine. There is no local environment for Vercel and like you said, Netlify's edge doesn't work locally.
Can this be prioritized? It's very cumbersome to use static assets with Cloudflare with unexpected outcome. Vercel and other can be added later
I've added support to the Netlify and Vercel adapters. Also added a test suite for Netlify now that the local dev environment supports edge functions.
I've added support to the Netlify and Vercel adapters. Also added a test suite for Netlify now that the local dev environment supports edge functions.
Thanks @eltigerchino. Apologies I couldn't find time to follow through with Netlify & Vercel. Appreciate you taking on the responsibility!
@eltigerchino I found a solution that avoids adding a new export: tweak SvelteKit's
readimplementation to handle async values. Could you take another look?
Thanks! That's a really nice solution.
I'm happy we have tests for the Netlify adapter now. However, adding netlify-cli pulls in almost 1,000 dependencies into the project: http://npmgraph.js.org/?q=netlify-cli. Is there some way we can serve the built files without netlify-cli? With all the recent supply chain attacks going on, I don't love the idea of having all these extra dependencies...
I think eventually we wanna turn these into "deploy to prod, do playwright stuff against prod url" tests. Slower but more reliable and fully replicates the environment
In the meantime I wonder if we could just invoke sirv since the only thing we do is call netlify serve. I'm not sure what all netlify serve does and it's probably not exactly the same, but it would be a lot lighter.
In the meantime I wonder if we could just invoke
sirvsince the only thing we do is callnetlify serve. I'm not sure what allnetlify servedoes and it's probably not exactly the same, but it would be a lot lighter.
I'm not sure how sirv would work with the Netlify build output. At least in https://github.com/sveltejs/kit/pull/12296 the CLI's serve is important for testing the split functions functionality with the Netlify middleware.
The Environment API integration is still far off, otherwise we could use the Netlify Vite plugin instead. I think Simon's idea might be a lot better and something we can implement sooner.
cc: @serhalp
I shared another idea here: https://github.com/e18e/ecosystem-issues/issues/156#issuecomment-3160886873