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

When using a placeholder in the Image component, there is an issue where the objectFit property may conflict with the backgroundSize property. #67478

Closed
qkrwogns9703 opened this issue Jul 5, 2024 · 8 comments · Fixed by #67482
Labels
Image (next/image) Related to Next.js Image Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@qkrwogns9703
Copy link
Contributor

qkrwogns9703 commented Jul 5, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/next-image-placeholder-kd57qw?file=%2Fapp%2FImageTest.tsx%3A12%2C16

To Reproduce

The issue can be reproduced by using the fill attribute in the Image component, setting style={{objectFit: 'fill'}}, and adding a data image URL to the placeholder props. This occurs when the placeholder's backgroundSize CSS property cannot use the objectFit property.

Current vs. Expected behavior

It might be perceived as not a bug, but since there can be situations where an invalid value is used for backgroundSize, I think we could perform a stricter type check.

packages/next/src/shared/lib/get-img-props.ts
스크린샷 2024-07-04 오후 12 36 00

When an objectFit property that cannot be used for backgroundSize is applied, I experienced an issue where the placeholder's size behaved unexpectedly. Please refer to the codesandbox link.

스크린샷 2024-07-05 오전 11 57 12 스크린샷 2024-07-05 오전 11 57 02

https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64
Binaries:
  Node: 18.17.0
  npm: 9.6.7
  Yarn: 1.22.10
  pnpm: 8.9.2
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 12.3.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Image (next/image)

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

No response

@hautest
Copy link

hautest commented Jul 8, 2024

I am also experiencing this problem, and it needs to be fixed.

@github-actions github-actions bot added the linear: next Confirmed issue that is tracked by the Next.js team. label Sep 16, 2024
@samcx
Copy link
Member

samcx commented Dec 18, 2024

@qkrwogns9703 Is there a reason why the :repro: is using next/dynamic?

@qkrwogns9703
Copy link
Contributor Author

@samcx Hello, there is no specific reason why next/dynamic should be used in this part. After running a few tests, the code wasn't cleaned up properly. I apologize for that. I've made the necessary changes in the CodesSandbox.

@samcx samcx removed the bug Issue was opened via the bug report template. label Feb 7, 2025
@samcx
Copy link
Member

samcx commented Feb 7, 2025

@qkrwogns9703 Sorry for the late response!

Can you clarify how it is behaving unexpectedly?

@qkrwogns9703
Copy link
Contributor Author

@samcx Hello, Thank you for your comment!
The issue I encountered was that I expected the placeholder to be filled based on the parent element, but it behaved differently than I anticipated.
The backgroundSize property does not support objectFit: 'fill'. However, when using the component and setting style={{ objectFit: "fill" }}, it applies objectFit: "fill" as a backgroundSize property, which I believe causes unexpected behavior.
So, I considered using the cover property instead when writing code that is not supported by the backgroundSize property.

@samcx
Copy link
Member

samcx commented Mar 10, 2025

@qkrwogns9703 I added a comment to your PR! → #67482 (comment)

@qkrwogns9703
Copy link
Contributor Author

@samcx Thank you for your comment! I have updated the changes in the Pull Request.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Image (next/image) Related to Next.js Image Optimization. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
4 participants
@samcx @qkrwogns9703 @hautest and others