-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: add getRemoteSize() to ImageService to enable customization of inferRemoteSize behavior
#15231
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 9d842f8 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this! It'll need a changeset and a docs PR to this page: https://docs.astro.build/en/reference/image-service-reference/. However, just a heads up that we'll be freezing main very soon, so this might only land in v6, which would take a month or two to be stable.
|
Understood. Thank you for the review and the approval! Regarding the changeset, should I create it as a |
|
It'll need to be a minor since it's a new feature! |
|
Thank you, I've added it. |
|
I previously brought over the comment for I’d like to update it to the following to better match the other properties. what do you think? /**
* Return the dimensions of a remote image.
*
* This is used to infer the width and height of an image from its URL,
* allowing the service to provide necessary metadata when it's not available locally.
*/
getRemoteSize?: (...) => … |
|
Also, I should probably rewrite the changeset as well. My apologies. |
|
I've updated the comments and the changeset. |
|
Hello! Apologies for the delayed response. This looks great! We're currently preparing for 6.x, so this will probably have to wait until we're ready for that to be merged. |
|
Thank you! |
|
If you have time rebasing onto next would be amazing! |
2db79ae to
c650369
Compare
|
Whoops, I must have done something wrong, a bunch of labels got added. |
|
| 📦 Package | 🔒 Before | 🔓 After |
|---|---|---|
| eslint-plugin-regexp | trusted-with-provenance | none |
| @cloudflare/kv-asset-handler | trusted-with-provenance | none |
| @cloudflare/unenv-preset | trusted-with-provenance | none |
| workerd | trusted-with-provenance | none |
| @sveltejs/vite-plugin-svelte-inspector | trusted-with-provenance | provenance |
| @sveltejs/vite-plugin-svelte | trusted-with-provenance | provenance |
| jsdoc-type-pratt-parser | trusted-with-provenance | none |
| miniflare | trusted-with-provenance | none |
| youch | provenance | none |
| @cloudflare/workerd-darwin-64 | trusted-with-provenance | none |
| @cloudflare/workerd-darwin-arm64 | trusted-with-provenance | none |
| @cloudflare/workerd-linux-64 | trusted-with-provenance | none |
| @cloudflare/workerd-linux-arm64 | trusted-with-provenance | none |
| @cloudflare/workerd-windows-64 | trusted-with-provenance | none |
| wrangler | trusted-with-provenance | none |
|
Only thing left is gonna be the PR to https://github.com/withastro/docs/ to update this page https://docs.astro.build/en/reference/image-service-reference/ ! Please target the |
Changes
As discussed in the issue #14515 and #15067, the current implementation of
inferRemoteSizehad the problem of increased network traffic because it did not cache data.To address this issue, I added a
getRemoteSizeproperty to the Image Service and implemented the publicly exposedinferRemoteSizeAPI to utilize this property.Additionally, for
baseService'sgetRemoteSize, I configured a function that simply wraps the existinginferRemoteSize. This ensures no breaking changes occur for users who do not wish to see their behavior altered.getRemoteSizeas an API of the Image Service.inferRemoteSizefunction to utilize the Image Service'sgetRemoteSize.inferRemoteSizefunction tobaseService'sgetRemoteSize. This prevents breaking changes and facilitates easy, lightweight extensions based on the existing implementation.Testing
I implemented tests to verify that arbitrary processing can be configured and that delegation from
baseServiceto the originalinferRemoteSizeis possible.Docs
Since we are setting the existing
inferRemoteSizeas the default value, I don't believe this constitutes a breaking change. However, since we will be introducing a new property calledgetRemoteSizein the Image Service, I think the documentation will need to be updated./cc @withastro/maintainers-docs
As this is a PR introducing a new property, I would like to hear the opinions of the maintainers regarding this approach.
Therefore, I will submit this PR as a draft for now.