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

fix(assets): add the missing await to getHTMLAttributes #8773

Conversation

sumimakito
Copy link
Contributor

@sumimakito sumimakito commented Oct 7, 2023

Changes

This pull request adds the missing await to properly use values returned by getHTMLAttribute in image services. It fixes an issue where HTML attributes do not render if getHTMLAttributes in an image service returns a Promise.

Minimum repro for this issue: StackBlitz (You can see that the custom HTML attributes are not rendered in the HTML if getHTMLAttribute returns a Promise instead a plain object)

Definition for getHTMLAttribute:

/**
* Return any additional HTML attributes separate from `src` that your service requires to show the image properly.
*
* For example, you might want to return the `width` and `height` to avoid CLS, or a particular `class` or `style`.
* In most cases, you'll want to return directly what your user supplied you, minus the attributes that were used to generate the image.
*/
getHTMLAttributes?: (
options: ImageTransform,
imageConfig: ImageConfig<T>
) => Record<string, any> | Promise<Record<string, any>>;

Testing

No tests were added as this is a one-line fix. It should have no impact if getHTMLAttributes returns a non-Promise.

Docs

No docs were needed as this fix does not change the expected behavior.

@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2023

🦋 Changeset detected

Latest commit: 4a96c79

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: astro Related to the core `astro` package (scope) label Oct 7, 2023
Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@Princesseuh Princesseuh merged commit eaed844 into withastro:main Oct 7, 2023
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Oct 7, 2023
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants