Skip to content
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

chore: update adapters to better support astro v5 #454

Merged
merged 21 commits into from
Jan 7, 2025

Conversation

alexanderniebuhr
Copy link
Member

@alexanderniebuhr alexanderniebuhr commented Nov 30, 2024

Changes

Testing

  • existing tests should still work

Docs

  • this specifically doesn't need docs, but I'll review the v5 docs anyways to make sure there updated to latest state

Copy link

changeset-bot bot commented Nov 30, 2024

🦋 Changeset detected

Latest commit: e874db6

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

This PR includes changesets to release 49 packages
Name Type
@astrojs/cloudflare Patch
@astrojs/test-utils Patch
@astrojs/netlify Patch
@astrojs/vercel Patch
@astrojs/node Patch
@test/astro-cloudflare-astro-dev-platform Patch
@test/astro-cloudflare-astro-env Patch
@test/astro-cloudflare-compile-image-service Patch
@test/astro-cloudflare-external-image-service Patch
@test/astro-cloudflare-wasm Patch
@test/astro-cloudflare-no-output Patch
@test/astro-cloudflare-routes-json Patch
@test/astro-cloudflare-with-solid-js Patch
@test/astro-cloudflare-with-svelte Patch
@test/astro-cloudflare-with-vue Patch
@test/astro-cloudflare-wrangler-preview-platform Patch
@test/netlify-hosted-astro-project Patch
@test/astro-vercel-basic Patch
@test/astro-vercel-image Patch
@test/vercel-isr Patch
@test/vercel-max-duration Patch
@test/vercel-edge-middleware-with-edge-file Patch
@test/vercel-edge-middleware-without-edge-file Patch
@test/astro-vercel-no-output Patch
@test/astro-vercel-prerendered-error-pages Patch
@test/astro-vercel-redirects-serverless Patch
@test/astro-vercel-redirects Patch
@test/vercel-server-islands Patch
@test/astro-vercel-serverless-prerender Patch
@test/astro-vercel-serverless-with-dynamic-routes Patch
@test/astro-vercel-static-assets Patch
@test/astro-vercel-static Patch
@test/vercel-streaming Patch
@test/astro-vercel-with-web-analytics-enabled-output-as-static Patch
vercel-hosted-astro-project Patch
@test/nodejs-api-route Patch
@test/nodejs-badurls Patch
@test/nodejs-encoded Patch
@test/nodejs-errors Patch
@test/nodejs-headers Patch
@test/nodejs-image Patch
@test/locals Patch
@test/node-middleware Patch
@test/nodejs-prerender-404-500 Patch
@test/nodejs-prerender Patch
@test/nodejs-preview-headers Patch
@test/node-trailingslash Patch
@test/url Patch
@test/well-known-locations Patch

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

@alexanderniebuhr
Copy link
Member Author

cc @florian-lefebvre any idea why /_image is not included in the routes anymore 🤔

@alexanderniebuhr
Copy link
Member Author

Thinking more bout this. /_image is injected. So maybe the hook runs too early to also include injected routes, but that would be a regression in my opinion 🤔

@florian-lefebvre
Copy link
Member

/_image should definitely be part of routes so there may be a bug there. In the tests I wrote it was in there (see https://github.com/withastro/astro/blob/main/packages/astro/test/units/integrations/api.test.js#L205-L211). How can I reproduce? By running a fixture locally?

@Fryuni
Copy link
Member

Fryuni commented Dec 2, 2024

There will be some cascading needed here or the adapter will install/require both Astro 4 and 5.
astro -> @inox-tools/astro-when -> @astrojs/cloudflare.

I'll release Astro When right after the official v5 tomorrow.

@alexanderniebuhr
Copy link
Member Author

@Fryuni I don't think it's related. The failing test should work without @inox-tools/astro-when

@alexanderniebuhr
Copy link
Member Author

@florian-lefebvre you can run the packages/cloudflare/test/routes-json.test.js tests manually. I just logged the routes array and it doesn't look like /_image is included.. I'm still trying to figure out if there is any config which is different here 🤔

@astrojs/cloudflare:test: routes [
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: true,
@astrojs/cloudflare:test:     entrypoint: 'src/mixed/pages/404.astro',
@astrojs/cloudflare:test:     pattern: '/404',
@astrojs/cloudflare:test:     params: [],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/404\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array] ],
@astrojs/cloudflare:test:     type: 'page',
@astrojs/cloudflare:test:     pathname: '/404',
@astrojs/cloudflare:test:     redirect: undefined,
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   },
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: false,
@astrojs/cloudflare:test:     entrypoint: 'src/mixed/pages/a/endpoint.ts',
@astrojs/cloudflare:test:     pattern: '/a/endpoint',
@astrojs/cloudflare:test:     params: [],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/a\/endpoint\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array], [Array] ],
@astrojs/cloudflare:test:     type: 'endpoint',
@astrojs/cloudflare:test:     pathname: '/a/endpoint',
@astrojs/cloudflare:test:     redirect: undefined,
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   },
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: false,
@astrojs/cloudflare:test:     entrypoint: '/a/redirect',
@astrojs/cloudflare:test:     pattern: '/a/redirect',
@astrojs/cloudflare:test:     params: [],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/a\/redirect\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array], [Array] ],
@astrojs/cloudflare:test:     type: 'redirect',
@astrojs/cloudflare:test:     pathname: '/a/redirect',
@astrojs/cloudflare:test:     redirect: '/',
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   },
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: false,
@astrojs/cloudflare:test:     entrypoint: 'src/mixed/pages/a/[id].astro',
@astrojs/cloudflare:test:     pattern: '/a/[id]',
@astrojs/cloudflare:test:     params: [ 'id' ],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/a\/([^/]+?)\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array], [Array] ],
@astrojs/cloudflare:test:     type: 'page',
@astrojs/cloudflare:test:     pathname: undefined,
@astrojs/cloudflare:test:     redirect: undefined,
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   },
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: true,
@astrojs/cloudflare:test:     entrypoint: 'src/mixed/pages/a/index.astro',
@astrojs/cloudflare:test:     pattern: '/a',
@astrojs/cloudflare:test:     params: [],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/a\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array] ],
@astrojs/cloudflare:test:     type: 'page',
@astrojs/cloudflare:test:     pathname: '/a',
@astrojs/cloudflare:test:     redirect: undefined,
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   },
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: false,
@astrojs/cloudflare:test:     entrypoint: 'src/mixed/pages/a/[...rest].astro',
@astrojs/cloudflare:test:     pattern: '/a/[...rest]',
@astrojs/cloudflare:test:     params: [ '...rest' ],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/a(?:\/(.*?))?\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array], [Array] ],
@astrojs/cloudflare:test:     type: 'page',
@astrojs/cloudflare:test:     pathname: undefined,
@astrojs/cloudflare:test:     redirect: undefined,
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   },
@astrojs/cloudflare:test:   {
@astrojs/cloudflare:test:     isPrerendered: true,
@astrojs/cloudflare:test:     entrypoint: 'src/mixed/pages/b/index.html',
@astrojs/cloudflare:test:     pattern: '/b',
@astrojs/cloudflare:test:     params: [],
@astrojs/cloudflare:test:     origin: 'project',
@astrojs/cloudflare:test:     generate: [Function (anonymous)],
@astrojs/cloudflare:test:     patternRegex: /^\/b\/?$/,
@astrojs/cloudflare:test:     segments: [ [Array] ],
@astrojs/cloudflare:test:     type: 'page',
@astrojs/cloudflare:test:     pathname: '/b',
@astrojs/cloudflare:test:     redirect: undefined,
@astrojs/cloudflare:test:     redirectRoute: undefined
@astrojs/cloudflare:test:   }
@astrojs/cloudflare:test: ]

@Fryuni
Copy link
Member

Fryuni commented Dec 2, 2024

Not related to the error, but related to this PR

@florian-lefebvre
Copy link
Member

I've tested a few things locally and I think the following is happening:

  • In dev, image route is always injected
  • In build, it's only injected if used
    We probably need confirmation from @Princesseuh on this

@Princesseuh
Copy link
Member

I've tested a few things locally and I think the following is happening:

  • In dev, image route is always injected
  • In build, it's only injected if used
    We probably need confirmation from @Princesseuh on this

The image endpoint should always be injected when the buildOutput is server. It'd be great if it was only injected when needed, but it's unfortunately not really possible.

@florian-lefebvre
Copy link
Member

Alright then it's possible I'm calling the hook right before those routes are injected, I'll check tomorrow

@florian-lefebvre
Copy link
Member

@alexanderniebuhr I've created a preview release [email protected] (withastro/astro#12597), can you try with that? I've tried locally but I think I was not updating the right packages

@alexanderniebuhr
Copy link
Member Author

alexanderniebuhr commented Dec 10, 2024

@florian-lefebvre it doesn't seem to change anything. Maybe I'm missing more here, but since the old hook works, this seems to be an issue with the new hook 🤔

@florian-lefebvre
Copy link
Member

That's weird, I'm going to look deeper now

@github-actions github-actions bot added pkg: netlify pkg: node Related to Node adapter (scope) pkg: vercel Related to Vercel adapter (scope) labels Dec 10, 2024
@florian-lefebvre
Copy link
Member

I updated all astro versions to the preview release so that the changes take effect for some reason. But there's one test failing now and it's unclear to me why. I think the fact that the server islands route is now part of the manifest changes how this test _routes.json is generated, so I don't know if it's a bug

@alexanderniebuhr
Copy link
Member Author

I'll check the test later, it might be an outdated assertion or it's a bug.

@monaye
Copy link

monaye commented Dec 12, 2024

@florian-lefebvre I am still new to Astro, but assuming, without this fix Image component wouldn't work in Server Islands for CloudFlare?

Here are the html output of Image component in Server Islands but all images are not loaded correctly (not showing up).

image

@florian-lefebvre
Copy link
Member

Hi @monaye I don't know actually! I think it's worth opening a new issue for what you're facing

@github-actions github-actions bot added pkg: netlify pkg: node Related to Node adapter (scope) pkg: vercel Related to Vercel adapter (scope) labels Dec 19, 2024
@florian-lefebvre
Copy link
Member

@alexanderniebuhr tests are now passing, can you double check the changes? I'll also do a ptal

@florian-lefebvre florian-lefebvre changed the title chore: update cloudflare adapter to support astro v5 chore: update adapters to better support astro v5 Dec 19, 2024
@lassegit
Copy link

Just a clarification; there was a general problem with deploying Astro v.5 to Cloudflare that will be fixed with this PR? Other PRs mentioned Vue as well.

@florian-lefebvre
Copy link
Member

It may not be fixed by this PR no

Copy link
Member Author

@alexanderniebuhr alexanderniebuhr left a comment

Choose a reason for hiding this comment

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

@florian-lefebvre I think it should be good to go. Have we adapted the adapterFeatures to fix #191 (comment) aswell?

Copy link
Member Author

@alexanderniebuhr alexanderniebuhr left a comment

Choose a reason for hiding this comment

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

@florian-lefebvre I think it should be good to go. Have we adapted the adapterFeatures to fix #191 (comment) too?

@alexanderniebuhr
Copy link
Member Author

there was a general problem with deploying Astro v.5 to Cloudflare that will be fixed with this PR

@lassegit What general problem are you talking about? If you mean the Vue/Svelte specific issues, they won't be fixed with this PR. However Astro v5 should be deployable to Cloudflare today.

@lassegit
Copy link

@alexanderniebuhr I just check with the latest dependencies and the issue seems resolved. Thanks.

@@ -476,6 +488,28 @@ export default function vercelAdapter({
};
}

function resolvedRouteToRouteData(
Copy link
Member

Choose a reason for hiding this comment

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

Do we plan to ultimately refactor this away? If so, maybe we can add a TODO here (and to the same functions copied in different adapters.)

Copy link
Member

Choose a reason for hiding this comment

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

Yes utlimately we need to update the function from the underscore redirects package, that would be breaking tho. Since it's in v0, I guess it'd be fine to ship the update as a minor.

Copy link
Member

Choose a reason for hiding this comment

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

I've created a linear task, I'll take care of it this week

@github-actions github-actions bot removed the pkg: node Related to Node adapter (scope) label Jan 7, 2025
@florian-lefebvre florian-lefebvre merged commit 83cedad into main Jan 7, 2025
8 checks passed
@florian-lefebvre florian-lefebvre deleted the cloudflare-astro-v5 branch January 7, 2025 15:52
@github-actions github-actions bot mentioned this pull request Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: cloudflare pkg: netlify pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The currently selected adapter @astrojs/cloudflare is not compatible with the image service "Sharp".
7 participants