Skip to content

Support Cloudflare Vite plugin v2 - #18119

Merged
ematipico merged 16 commits into
withastro:nextfrom
jamesopstad:support-cloudflare-vite-plugin-v2
Sep 28, 2026
Merged

ematipico merged 16 commits into
withastro:nextfrom
jamesopstad:support-cloudflare-vite-plugin-v2

Conversation

@jamesopstad

@jamesopstad jamesopstad commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #18112.

Until that PR lands, the focused diff is:
jamesopstad/astro@resolved-vite-output-dirs...support-cloudflare-vite-plugin-v2

Changes

Updates the adapter to use v2 of @cloudflare/vite-plugin and support deployment with cf.

Projects should replace Wrangler configuration with cloudflare.config.ts, importing configuration utilities from cf/config. cf should also be used in place of Wrangler for deployment.

The adapter’s configPath option has been removed. Configuration is always loaded from a cloudflare.config.ts file in the project root.

wrangler is no longer a peer dependency of @astrojs/cloudflare.

Testing

Tests updated as appropriate.

Docs

withastro/docs#14614

@changeset-bot

changeset-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79b5018

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/cloudflare Major

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

@jamesopstad jamesopstad changed the title Support cloudflare vite plugin v2 Support Cloudflare Vite plugin v2 Sep 24, 2026
@github-actions github-actions Bot added the semver: minor Change triggers a `minor` release label Sep 24, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@github-actions github-actions Bot added pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) docs pr labels Sep 24, 2026
@jamesopstad
jamesopstad force-pushed the support-cloudflare-vite-plugin-v2 branch from 3f1e57c to c6357ef Compare September 24, 2026 13:33
@jamesopstad
jamesopstad marked this pull request as ready for review September 24, 2026 13:47
@ematipico ematipico added the pr: astro-review Triggers a bot to do an automated review label Sep 24, 2026
@astro-factory astro-factory Bot removed the pr: astro-review Triggers a bot to do an automated review label Sep 24, 2026
Comment thread .changeset/calm-apes-build.md Resolved
Comment thread .changeset/curly-clouds-configure.md Resolved
Comment thread .changeset/tidy-spiders-build.md Outdated
Comment on lines +1 to +5
---
'astro': minor
---

Astro now treats Vite's resolved `outDir` values as the source of truth for build output. Generated assets, build hook `dir` values, and SSR manifest paths use the resolved client, server, and prerender directories. Custom prerenderer factories also receive these directories through a new context argument.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would rewrite this changeset from the user point of view.

Comment on lines -494 to -500
if (cloudflareOptions.configPath) {
addWatchFile(new URL(cloudflareOptions.configPath, config.root));
}

addWatchFile(new URL('./wrangler.toml', config.root));
addWatchFile(new URL('./wrangler.json', config.root));
addWatchFile(new URL('./wrangler.jsonc', config.root));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't we need to watch the new configuration file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that depends on how Astro restarts interact with Vite restarts. We restart the Vite dev server when the config file or any of its dependencies change. Watching it here would be tricky because you don't know its dependencies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would check to make sure restarting the dev server in Astro works that same as in vite dev, it might not.

@jamesopstad jamesopstad Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I got an agent to investigate this. Here is its reply:

The Cloudflare plugin already watches cloudflare.config.ts and its dependencies, so watching only the top-level file here would be incomplete and would cause both Astro and Cloudflare to initiate restarts. However, Matthew’s concern uncovered an Astro lifecycle issue: Vite replaces its watcher during a native restart, and Astro’s externally registered restart/content listeners are not reattached after a plugin-initiated restart. We should fix that listener lifecycle and add an astro dev regression test rather than restore addWatchFile() here.

"peerDependencies": {
"astro": "^7.2.0",
"wrangler": "^4.125.0"
"astro": "^7.4.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this change intentional? We usually don't bump it unless we need a specific API from astro

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR relies on #18112, which makes changes to Astro core, so I assumed that would require the bump?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I see. Makes sense then. So I suggest #18112 to main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will change this to 7.4.0-beta.0

@github-actions github-actions Bot removed the docs pr label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) semver: minor Change triggers a `minor` release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants