Skip to content

feat: add support for read in edge environments #13859

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

vnphanquang
Copy link
Contributor

@vnphanquang vnphanquang commented Jun 5, 2025

closes #12446
closes #11674

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:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Jun 5, 2025

🦋 Changeset detected

Latest commit: f93ad3d

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 Major
@sveltejs/adapter-vercel Major
@sveltejs/adapter-cloudflare Major
@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

@svelte-docs-bot
Copy link

@vnphanquang
Copy link
Contributor Author

vnphanquang commented Jun 5, 2025

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!

image

@eltigerchino
Copy link
Member

eltigerchino commented Jun 6, 2025

Thanks for this PR! Is there any chance you could continue the work from #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.

@vnphanquang
Copy link
Contributor Author

Ah yes. Sorry I missed Rich's PR in my search. Will look into it. Thanks for the input!

@vnphanquang vnphanquang force-pushed the 12446 branch 2 times, most recently from dc18769 to 6da55ed Compare June 6, 2025 06:20
@vnphanquang
Copy link
Contributor Author

vnphanquang commented Jun 6, 2025

@eltigerchino extracted into a streamFileContent function via 6da55ed. 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 think kit is already a peer-dependency for all adapters anyway,
  • settled with this name rather than fetchFile since I feel like fetch would indicate a returned Response.

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

@vnphanquang vnphanquang requested a review from eltigerchino June 6, 2025 06:36
@eltigerchino
Copy link
Member

Thank you!

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?

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.

@eltigerchino eltigerchino changed the title feat: add support for server read in cloudflare adapter feat: add support for read in edge environments Jun 6, 2025
@eltigerchino eltigerchino added adapters - general Support for functionality general to all adapters and removed pkg:adapter-cloudflare labels Jun 6, 2025
@vladshcherbin
Copy link

Can this be prioritized? It's very cumbersome to use static assets with Cloudflare with unexpected outcome. Vercel and other can be added later

@eltigerchino
Copy link
Member

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.

@vnphanquang
Copy link
Contributor Author

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!

"index.js",
"utils.js",
"index.d.ts",
"ambient.d.ts"
],
"scripts": {
"dev": "node -e \"fs.rmSync('files', { force: true, recursive: true })\" && rollup -cw",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a nicer way to handle clearing files? ideally the rollup call would take care of it if files is part of it?

Copy link
Member

@eltigerchino eltigerchino Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently do this for adapter-netlify, adapter-node, and adapter-vercel. Would it be a good soution to add a simple plugin such as below?

/**
 * @param {string} filepath
 * @returns {import('rollup').Plugin}
 */
function clearOutput(filepath) {
	return {
		name: 'clear-output',
		buildStart: {
			order: 'pre',
			sequential: true,
			handler() {
				rmSync(filepath, { recursive: true, force: true });
			}
		}
	};
}

"index.js",
"utils.js",
"index.d.ts",
"ambient.d.ts"
],
"scripts": {
"dev": "node -e \"fs.rmSync('files', { force: true, recursive: true })\" && rollup -cw",
"build": "node -e \"fs.rmSync('files', { force: true, recursive: true })\" && rollup -c && node -e \"fs.cpSync('src/serverless.js', 'files/serverless.js');\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters - general Support for functionality general to all adapters pkg:adapter-cloudflare pkg:adapter-netlify pkg:adapter-vercel Pertaining to the Vercel adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support ot $app/server read() method to cloudflare pages adapter
4 participants