Request for feedback: Image Component ‘Raw’ layout #35776
Replies: 13 comments 1 reply
-
Hi, I am using Next with Typescript and it seems that layout="raw" causes an error because Typescript doesn't recognize "raw", as I am trying to position the Image as relative. in VSCode : |
Beta Was this translation helpful? Give feedback.
-
yup, seeing the same error: |
Beta Was this translation helpful? Give feedback.
-
You'll need to update to Next.js 12.1.1 or newer: |
Beta Was this translation helpful? Give feedback.
-
Seems to be working well with TypeScript here.
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 I think that it should be possible to allow for the user to supply alternative
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 |
Beta Was this translation helpful? Give feedback.
-
Take a look how Imgix handles picture tag for art direction https://reactjsexample.com/react-component-to-display-imgix-images/. Something like this is desperately needed in nextjs.
|
Beta Was this translation helpful? Give feedback.
-
I just tried out the raw layout. What layout / styling behavior were you previously unable to accomplish with next/image?I had a menu dropdown that overlayed some next/image instances. The next.js Image component created its own stacking context independent of the absolute-positioned dropdown, and no amount of cajoling or convincing made the stacking context of the images appear lower in the 3d layout of the page than the menu. I skimmed the source of next/image and it seemed like it wasn't configurable enough to remove the style data responsible for creating the independent stacking context. I found other bugs where the recommendation was to make the other element have a different position type, which I could not do because my dropdown requires What layout modes did you try?I cycled through all of them, but I did not read the documentation on any of them ; I was sick of wrestling with z-indices and stacking contexts at this point and was just hoping one would insta-work. 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?This worked as a drop-in replacement for my specific use case, so it's hard to say. |
Beta Was this translation helpful? Give feedback.
-
I also think that it doesn't make any sense to base image sizes generation (1x, 2x) on some array of constants defined in If I have a 1200x800 image in 2x DPI and want to support generation of 1x, 2x sizes with the fixed/raw layout, I have to do this:
And then in
This is incredibly frustrating and error-prone. Right now this array is bloating up to 100+ entries to support all images on my site. NextJS Image should support generating this automatically. |
Beta Was this translation helpful? Give feedback.
-
because 'raw' has image format connotations. Maybe consider using layout="none" or layout="vanilla" ? |
Beta Was this translation helpful? Give feedback.
-
This is less feedback for raw and more just next image in general, but because safari (which obviously has a huge amount of market share) doesn't support imagesrcset on preloads, our LCP gets hurt pretty bad. I have a bit of a hack where I preload my own (reasonably large with low quality) image right "behind" (using z-index) a next image and it seems to kind of work, but it'd be nice if next image had something nice for Safari. I think the downside here is that webvitals doesn't count on Safari. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Strict CSP rules, not allowing any inline styles / scripts etc.
All of them
Mostly, the raw layout still adds a style attribute with aspect ratio though. It doesn't break the image or anything, the image still works as intended, but my CSP policy still chucks out errors in the console.
Not sure if there's a reason that this is being added, but perhaps if we could turn it off? Pass a prop the disables all inline-styles from being applied? |
Beta Was this translation helpful? Give feedback.
-
This isn't 100% related to the raw layout, but wanted to mention it here as I close out the discussion. We have extracted the core logic from This allows usage outside of
Exampleimport { unstable_getImgProps as getImgProps } from 'next/image'
export default function Page() {
const common = { alt: 'Hero', width: 800, height: 400 }
const { props: { srcSet: dark } } = getImgProps({ ...common, src: '/dark.png' })
const { props: { srcSet: light, ...rest } } = getImgProps({ ...common, src: '/light.png' })
return (<picture>
<source media="(prefers-color-scheme: dark)" srcSet={dark} />
<source media="(prefers-color-scheme: light)" srcSet={light} />
<img {...rest} />
</picture>)
} PR: #51205 |
Beta Was this translation helpful? Give feedback.
-
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 asizes
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 thenext/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:
next/image
?”raw”
layout mode solve your problem? - If not, what changes would allow it to solve the problem?Beta Was this translation helpful? Give feedback.
All reactions