Skip to content

Restore parity for Cloudflare custom worker entrypoints - #17708

Closed
matthewp wants to merge 4 commits into
mainfrom
triage-17600
Closed

Restore parity for Cloudflare custom worker entrypoints#17708
matthewp wants to merge 4 commits into
mainfrom
triage-17600

Conversation

@matthewp

@matthewp matthewp commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Changes

Testing

  • Expands custom-entrypoint coverage for cookies, sessions, cache headers, assets, Hono, and prerendering.
  • Adds FetchState and mutable/immutable response finalization tests.

Docs

@changeset-bot

changeset-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dd89c58

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

@github-actions github-actions Bot added pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release labels Aug 15, 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.

@codspeed-hq

codspeed-hq Bot commented Aug 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing triage-17600 (dd89c58) with main (3193988)

Open in CodSpeed

# Conflicts:
#	packages/integrations/cloudflare/test/custom-entryfile-fetch-state.test.ts
@matthewp
matthewp marked this pull request as ready for review August 27, 2026 13:40
/** Applies the registered response finalizers in registration order. */
finalize(response: Response): Response;
/** Returns whether the request matched an Astro route before fallback handling. */
hasMatchedRoute(): boolean;

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.

It seems we need docs. Those are public methods, we should add them alongside rewrite() in https://docs.astro.build/en/reference/modules/astro-fetch/#methods

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.

Yep, done here: withastro/docs#14476

# Conflicts:
#	packages/integrations/cloudflare/src/index.ts
Comment thread .changeset/silver-chefs-serve.md Outdated
@@ -0,0 +1,26 @@
---
'astro': minor
'@astrojs/cloudflare': patch

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.

The minor is only for astro though. Cloudflare is just a fix that requires this new minor

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.

Are you saying that the Cloudflare adapter should also be a minor?

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 think so, because without the astro new minor, the "parity" can't be restored. At least, that's what I understood from the PR. Which means peerDependencies#astro of the @astrojs/cloudflare package should be 7.3 (the upcoming minor)

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.

Makes sense, will update.

Comment on lines +2 to +3
'astro': minor
'@astrojs/cloudflare': patch

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.

Same

Comment on lines +123 to +126
* Registers a finalizer that runs after Astro renders a response.
* Finalizers run in registration order and may mutate or replace the response.
*/
addResponseFinalizer(finalizer: (response: Response) => Response): void;

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 don't understand why this exists. What about middleware? This is a provocative question, because docs don't mention that.

I believe it's important you highlight the differences.

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.

Do you mean Astro middleware?

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.

Just to answer here, the reason not to use Astro middleware doesn't change with this feature, it's the same reason as before, namely that:

  1. Astro middleware doesn't give you control over the order that Astro features run (ie you can't run your own code before Actions).
  2. Astro middleware is not the Fetch API and is not compatible with Hono (and its ecosystem).

This feature is intended to solve something that didn't get solved with the v1 of advanced routing, there not being a pattern for handling responses. So handlers that need a response are doing it different ways:

So after this, these APIs and similar can just take take a FetchState.

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.

Yes I meant Astro middleware.

Thank you for the explanation. If I can give you and advice, I would try to explain why this feature exists and what it solves. Something that the middleware can't. It seems to be a very advanced API though, right?

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.

There's nothing that this new addResponseFinalizer API can do that middleware can't, middleware can mutate responses. But advanced routing can do things middleware can't, and that's already explained here: https://docs.astro.build/en/guides/routing/#advanced-routing

I'm not sure if this is what you're looking for, but the reason to use addResponseFinalizer and not Astro middleware is that you are already using advanced routing. You wouldn't normally use both advanced routing and Astro middleware. You might if you have an existing project which already use Astro middleware and don't want to migrate. But I don't know that addResponseFinalizer docs is the right place to explain that.

Would adding a new "Why not Astro middleware" section to the advanced routing docs satisfy this concern?

@ematipico ematipico Sep 1, 2026

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.

You wouldn't normally use both advanced routing and Astro middleware.

Why not? I thought one of the reasons for using advanced routing was to change the order of the Astro's operations (redirects, middleware, actions, etc.)

Would adding a new "Why not Astro middleware" section to the advanced routing docs satisfy this concern?

Probably yes!

@matthewp

matthewp commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

I'm moving this back to draft based on the discussion about with @ematipico, I'm thinking about how this new API conflicts with the Hono API.

@matthewp
matthewp marked this pull request as draft September 1, 2026 18:42
@matthewp matthewp removed this from the 7.3 milestone Sep 2, 2026
@matthewp

matthewp commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #17887.

@matthewp matthewp closed this Sep 2, 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.

cf() is missing four things handle() does: cookies/sessions, the CDN no-store default, the assets fallback, the prerender phase

3 participants