Request for feedback: Image Component ‘Raw’ layout
See original GitHub issueStarting 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:
- What layout / styling behavior were you previously unable to accomplish with
next/image
? - 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? - Do you have any additional feedback about the new mode or its documentation?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top GitHub Comments
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.
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:
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
orfill
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 usingfixed
orraw
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 separatewidth
andheight
for each) for alternative media breakpoints.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
.You’ll need to update to Next.js 12.1.1 or newer:
npm i next@latest
oryarn add next@latest