Skip to content

Conversation

@yanthomasdev
Copy link
Member

@yanthomasdev yanthomasdev commented May 17, 2025

Changes

This PR makes a few changes for logs in the Cloudflare adapter's dev server based on feedback from withastro/adapters#191 and my experience using it.

Here's the log you would get when starting the dev server with the Cloudflare adapter:

12:50:48 [@astrojs/cloudflare] Enabling sessions with filesystem storage. Be sure to define a KV binding named "SESSION".
12:50:48 [@astrojs/cloudflare] If you see the error "Invalid binding `SESSION`" in your build output, you need to add the binding to your wrangler config file.
12:50:48 [WARN] [config] The adapter @astrojs/cloudflare has limited support for "sharp". Certain features may not work as expected.
12:50:48 [WARN] [adapter] Cloudflare does not support sharp. You can use the `compile` image service to compile images at build time. It will not work for any on-demand rendered images.

Respectively, here are my thoughts and solutions:

  1. The first log says it's enabling sessions with filesystem storage, but asks you to define a KV binding name, which sounds confusing.
    — Changed it so it clarifies it will enable it for production usage, and the follow-up docs PR will add information about the Sessions behavior during dev.

  2. Again, if I am using the filesystem storage, why would that matter?
    — Made so this log is only shown during build. That's when you'd get the mentioned error and the information would be most relevant to be shown to you, plus making the dev startup logs one line shorter.

  3. Limited support, ok! How exactly limited, though?
    — Clarified that you can still use sharp during build time, but not runtime, meaning only pre-rendered pages will get optimized.

  4. Now its no support at all? Also, this says you can use the compile image service, but using it doesn't make the warning go away, and in a kind of funny way, I was totally unaware it actually uses sharp, which I was just told was not compatible at all, so...? 😆
    — Clarified the compile option means using sharp.

NOTE: Not really sure if this is a patch or a minor change? 😅

Testing

I am not sure how/if I am supposed to test CLI logs automatically, but for manual testing:

  • Build packages/integrations/cloudflare with this branch's changes.
  • Run the dev server with and without an imageService option set.
  • Then, run the build command to see the warning about session storage on build.

The expected behavior is to get the two warnings about sharp with @astrojs/cloudflare while no imageService is set, but when set, it is suppressed. And the tip about the "invalid session storage" to only be shown during the build process.

Docs

Sibling docs PR: withastro/docs#11708

/cc @withastro/maintainers-docs for feedback!

@changeset-bot
Copy link

changeset-bot bot commented May 17, 2025

🦋 Changeset detected

Latest commit: 3191a96

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 the pkg: integration Related to any renderer integration (scope) label May 17, 2025
if (config.service.entrypoint === 'astro/assets/services/sharp') {
logger.warn(
`The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'noop' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`,
`The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'passthrough' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`,
Copy link
Member Author

Choose a reason for hiding this comment

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

A bit of an extra, the option name itself is not noop (although yes, it's a non-operational service). Mostly to make things consistent.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

The logged messages look good to me, Yan! One small suggestion below to see if we can make one a little easier to read. Approving for docs/messages!

);
logger.info(
`If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`,
`Enabling sessions with Cloudflare KV for production with the "${bindingName}" KV binding.`,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is misleading because in dev it's not using CLoudflare KV. I'd move this inside the conditional block

Copy link
Member Author

Choose a reason for hiding this comment

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

It does say it's Cloudflare KV for production, so I wouldn't think that would apply in dev if I were reading that.

I am not against moving this into the conditional, though! I was thinking, and I guess most people wanting to use Sessions will either look into the docs and configure manually or see the Cloudflare adapter docs and just use the default config, so being reminded of this in dev might not be necessary.

Copy link
Member

@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.

I would prefer if core actually allows the adapter to control when messages will be logged instead of using a "hacky" workaround, but it works for me.

@ematipico
Copy link
Member

From this PR it's clear that the supporting feature needs to be more flexible and intelligent, so I wonder:

  • why aren't we making PRs against it?
  • do we plan to track those suggestions somewhere?

@alexanderniebuhr
Copy link
Member

@ematipico IIRC in the past I was told we don't want to change the logic in core, and the adapter should find a way to work-around it, but it that changed, we can track the idea and try to open PRs.

@ascorbic
Copy link
Contributor

I agree with @ematipico. Let's fix this in core rather than hacking around it.

@yanthomasdev
Copy link
Member Author

I made a PR to track and propose a way to fix this in core: #13842

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr semver: minor Change triggers a `minor` release labels Jun 3, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

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
Copy link

codspeed-hq bot commented Jun 3, 2025

CodSpeed Performance Report

Merging #13817 will not alter performance

Comparing cloudflare-log-improv (2137869) with main (442b841)

Summary

✅ 6 untouched benchmarks

@yanthomasdev
Copy link
Member Author

Added a changeset for the changes in @astrojs/cloudflare. I assume it's a minor since we are using a new option in Astro core, let me know if it should be a patch instead.

@ascorbic ascorbic changed the base branch from main to suppress-supported-features-log-option June 3, 2025 13:31
@ascorbic ascorbic force-pushed the cloudflare-log-improv branch from 2137869 to ba9360a Compare June 3, 2025 13:35
@github-actions github-actions bot removed pkg: astro Related to the core `astro` package (scope) docs pr labels Jun 3, 2025
@ascorbic
Copy link
Contributor

ascorbic commented Jun 3, 2025

Merge after #13887

Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

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

Much better! No more gambiarra fixes!

Base automatically changed from suppress-supported-features-log-option to main June 4, 2025 10:01
@ascorbic ascorbic dismissed github-actions[bot]’s stale review June 4, 2025 10:04

tryna strike a chord

@ascorbic ascorbic merged commit b7258f1 into main Jun 4, 2025
2 of 5 checks passed
@ascorbic ascorbic deleted the cloudflare-log-improv branch June 4, 2025 10:04
@astrobot-houston astrobot-houston mentioned this pull request Jun 4, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
…ro#13817)

* Clarify and reduce Cloudflare integration logs

* Simplify log

Co-authored-by: Sarah Rainsberger <[email protected]>

* Move enabling sessions log to only show in build

* Use double quotes instead

* Add option to suppress adapter feature support log

* Add fixture to test option

* Add changeset

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Matt Kane <[email protected]>

* Use `suppress` option instead of hack

* Create fast-planets-shout.md

* Update .changeset/fast-planets-shout.md

Co-authored-by: Matt Kane <[email protected]>

---------

Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants