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

[ BUG ] OptimizeImages throws warning when dimension values are set to 0 #193

Open
sasjakoning opened this issue Jan 22, 2025 · 0 comments

Comments

@sasjakoning
Copy link

sasjakoning commented Jan 22, 2025

Framework: Nuxt.js

When using the richTextResolver with the optimizeImages function, setting the width and/or right to 0 throws the following warning:

[StoryblokRichText] - Height value must be a number greater than 0

While this may be the expected behaviour, it doesn't align well with the image service documentation as stated here: https://www.storyblok.com/docs/image-service#resizing In which a dimension could be set to 0 to enable proportional sizing.

On the page itself, it does work correctly, but it still throws the warning.

I do understand that setting explicit width and height values is best practice to avoid content shifting and such. But, when I, for example, set the values to 500x500, the image is cropped and cannot be adjusted using rules such as object-fit: contain;.

Image
(Example of images being cropped when static width/height values are set)

An alternative to fix this would be to add the fit-in option as documented in the image service: https://www.storyblok.com/docs/image-service#fit-in

I have also mentioned this issue in the Storyblok Discord server: https://discord.com/channels/700316478792138842/1331278280179060878


Expected Behavior

No longer show a warning when using '0' as a dimension value.

Or,

Images with fixed width and height don't crop or can be adjusted using fit-in options.

Current Behavior

The code throws a warning when setting the dimension width and/or height to '0'.

Steps to Reproduce

this is the code I used to render my images in this I got the warning

[StoryblokRichText] - Height value must be a number greater than 0

const { render } = richTextResolver({
    optimizeImages: {
        width: 500,
        height: 0,
        filters: {
            format: 'webp',
        },
    },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant