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

NextImage loader doesn't correctly set the width and height params #1646

Open
mg-aceik opened this issue Oct 31, 2023 · 2 comments
Open

NextImage loader doesn't correctly set the width and height params #1646

mg-aceik opened this issue Oct 31, 2023 · 2 comments
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug

Comments

@mg-aceik
Copy link

mg-aceik commented Oct 31, 2023

Describe the Bug

NextImage loader doesn't correctly set the width and height params on the url depending on the fill value. This results in Sitecore image processor to add black borders to the image depending on its size.

It returns srcset with values like /-/jssmedia/test.jpg?h=1705&iar=0&w=2740&rev=7a67deeaa84446e69d7bbafbe2d4baf4&mw=640

To Reproduce

<NextImage
  field={props.fields.image}
  fill 
  sizes="100vw" />

Expected Behavior

srcset with values like /-/jssmedia/test.jpg?iar=0&amp;rev=7a67deeaa84446e69d7bbafbe2d4baf4&amp;mw=640
In other words, strip out the height and width params.

Possible Fix

Update the sitecoreLoader to remove these params if the fill param is passed, similar to how it is done on the props themselves.

Provide environment information

  • Sitecore Version: XM Cloud
  • JSS Version: 21.5.0
@Juansereina
Copy link

I'm experiencing the same issue. I've written a custom loader to remove the h and w properties, and I use it in the image component when I add the fill attribute.

// src/lib/sitecore-loader-override

import { ImageLoader, ImageLoaderProps } from 'next/image';

export const sitecoreLoader: ImageLoader = ({
  src,
  width,
}: ImageLoaderProps): string => {
  const [root, paramString] = src.split('?');
  const params = new URLSearchParams(paramString);
  params.set('mw', width.toString());

  // custom change
  params.delete('h');
  params.delete('w');

  return `${root}?${params}`;
};
import { sitecoreLoader } from 'lib/sitecore-loader-override';

<NextImage
  field={props.fields.image}
  fill
  loader={sitecoreLoader}
/>

@illiakovalenko
Copy link
Contributor

@mg-aceik Thank you for submitting your contribution! I've added a ticket containing all the details. It has been added to our internal backlog for thorough review

@illiakovalenko illiakovalenko added the backlog Issue/PR/discussion is reviewed and added to backlog for the further work label Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issue/PR/discussion is reviewed and added to backlog for the further work 🐞 bug
Projects
None yet
Development

No branches or pull requests

3 participants