question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request for feedback: Image Component ‘Raw’ layout

See original GitHub issue

Starting with version 12.1.1-canary.11, I’ve added experimental support for a new image component mode layout mode called “raw”. This mode removes the spacers and styling associated with next/image’s responsive behavior, rendering a “raw” image element with no styling. The component still requires height and width information in order to prevent layout shift, and will pass those attributes to the underlying image unless you also provide a sizes attribute, which indicates that the image is expected to behave responsively.

I have also enabled the use of the style attribute in all image modes to pass style properties directly to the underlying image element. Be aware that in layout modes other than ”raw”, any styling required for that layout mode will take precedence over provided styling, if there’s a conflict.

I would like to gather feedback on the new ”raw” layout mode before we move it out of experimental. I encourage anyone who’s had trouble getting the next/image component styled the way they want to try the experimental ”raw” layout and tell me how it worked.

See this section in the documentation for how to enable the experimental layout mode.


Here’s an example template for responses, though any feedback is appreciated:

  1. What layout / styling behavior were you previously unable to accomplish with next/image?
  2. What layout modes did you try?
  3. Did the experimental ”raw” layout mode solve your problem?
 - If not, what changes would allow it to solve the problem?
  4. Do you have any additional feedback about the new mode or its documentation?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
OskarGrothcommented, Mar 27, 2022

Seems to be working well with TypeScript here. This is a great addition, it solves many issues with layout that I’ve experienced while using Image. But still doesn’t cover the one use case I think the Image component lacks the most.

What layout / styling behavior were you previously unable to accomplish with next/image?

The image component desperately needs a way to define art direction. That is, to be able to provide different images at different breakpoints.

i.e, something that matches the following:

<picture>
    <source srcset="mobile.jpg 1x, mobile_2x.jpg 2x" media="(max-width:734px)">
    <source srcset="desktop.jpg 1x, desktop_2x.jpg 2x" media="(min-width:0px)">
    <img src="desktop.jpg">
</picture>

What layout modes did you try? Did the experimental ”raw” layout mode solve your problem?
 - If not, what changes would allow it to solve the problem?

I’ve tried all layout modes. The problem stems from the fact that the developer has very limited control over the generated srcsets.

Either you use responsive or fill and have your image generated in like 10 different sizes (none of which are relevant because I only want my image generated in 1x or 2x size). Or you define width & height while using fixed or raw and get precise 1x and 2x sizes. But there is no way to do that while also defining a different image for a different viewport.

I think that it should be possible to allow for the user to supply alternative src (with separate width and height for each) for alternative media breakpoints.

Do you have any additional feedback about the new mode or its documentation?

The documentation lacks a demo, instead there is a link to “Demo Background Image” which is a bit confusing since it doesn’t seem to be using raw.

1reaction
styflecommented, Mar 25, 2022

You’ll need to update to Next.js 12.1.1 or newer: npm i next@latest or yarn add next@latest

Read more comments on GitHub >

github_iconTop Results From Across the Web

next/image - Next.js
This next/image component uses browser native lazy loading, which may fallback to eager loading for older browsers before Safari 15.4.
Read more >
Houssein Djirdeh on Twitter: "Thanks to @atcastle, a new "raw ...
a new "raw" layout mode is coming to the Next.js Image component to allow anyone to take full control of styling and wrapping...
Read more >
Raw Image | Unity UI | 1.0.0 - Unity - Manual
Raw Image. The Raw Image control displays a non-interactive image to the user. You can use this for purposes such as decorations or...
Read more >
Enhance fine details in raw images - Adobe Support
Apply Raw Details. In the Library or Develop module, select a supported image that you want to enhance. Do one of the following:....
Read more >
Image - .NET MAUI | Microsoft Learn
NET MAUI Image displays an image that can be loaded from a local file, a URI, ... unless the size of the Image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found