Unverified Commit 5ea3f6c4 authored by Steven's avatar Steven Committed by GitHub

Remove layout raw image experiment (#38006)

This PR removes experimental `layout="raw"` from `next/image` since it was moved to `next/future/image` in #37927 
parent 42e214e5
...@@ -15,8 +15,8 @@ description: Enable Image Optimization with the built-in Image component. ...@@ -15,8 +15,8 @@ description: Enable Image Optimization with the built-in Image component.
<summary><b>Version History</b></summary> <summary><b>Version History</b></summary>
| Version | Changes | | Version | Changes |
| --------- | ----------------------------------------------------------------------------------------------------- | | --------- | --------------------------------------------------------------------------------------------------------- |
| `v12.2.0` | Experimental `remotePatterns` and experimental `unoptimized` configuration added. | | `v12.2.0` | Experimental `remotePatterns` and experimental `unoptimized` configuration added. `layout="raw"` removed. |
| `v12.1.1` | `style` prop added. Experimental[\*](#experimental-raw-layout-mode) support for `layout="raw"` added. | | `v12.1.1` | `style` prop added. Experimental[\*](#experimental-raw-layout-mode) support for `layout="raw"` added. |
| `v12.1.0` | `dangerouslyAllowSVG` and `contentSecurityPolicy` configuration added. | | `v12.1.0` | `dangerouslyAllowSVG` and `contentSecurityPolicy` configuration added. |
| `v12.0.9` | `lazyRoot` prop added. | | `v12.0.9` | `lazyRoot` prop added. |
...@@ -51,7 +51,7 @@ When using an external URL, you must add it to ...@@ -51,7 +51,7 @@ When using an external URL, you must add it to
The `width` property can represent either the _rendered_ width or _original_ width in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties. The `width` property can represent either the _rendered_ width or _original_ width in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.
When using `layout="intrinsic"`, `layout="fixed"`, or `layout="raw"`, the `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears. When using `layout="intrinsic"` or `layout="fixed"` the `width` property represents the _rendered_ width in pixels, so it will affect how large the image appears.
When using `layout="responsive"`, `layout="fill"`, the `width` property represents the _original_ width in pixels, so it will only affect the aspect ratio. When using `layout="responsive"`, `layout="fill"`, the `width` property represents the _original_ width in pixels, so it will only affect the aspect ratio.
...@@ -61,7 +61,7 @@ The `width` property is required, except for [statically imported images](/docs/ ...@@ -61,7 +61,7 @@ The `width` property is required, except for [statically imported images](/docs/
The `height` property can represent either the _rendered_ height or _original_ height in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties. The `height` property can represent either the _rendered_ height or _original_ height in pixels, depending on the [`layout`](#layout) and [`sizes`](#sizes) properties.
When using `layout="intrinsic"`, `layout="fixed"`, or `layout="raw"`, the `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears. When using `layout="intrinsic"` or `layout="fixed"` the `height` property represents the _rendered_ height in pixels, so it will affect how large the image appears.
When using `layout="responsive"`, `layout="fill"`, the `height` property represents the _original_ height in pixels, so it will only affect the aspect ratio. When using `layout="responsive"`, `layout="fill"`, the `height` property represents the _original_ height in pixels, so it will only affect the aspect ratio.
...@@ -76,12 +76,11 @@ The `<Image />` component accepts a number of additional properties beyond those ...@@ -76,12 +76,11 @@ The `<Image />` component accepts a number of additional properties beyond those
The layout behavior of the image as the viewport changes size. The layout behavior of the image as the viewport changes size.
| `layout` | Behavior | `srcSet` | `sizes` | Has wrapper and sizer | | `layout` | Behavior | `srcSet` | `sizes` | Has wrapper and sizer |
| ---------------------------------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | -------- | --------------------- | | --------------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------- | --------------------- |
| `intrinsic` (default) | Scale *down* to fit width of container, up to image size | `1x`, `2x` (based on [imageSizes](#image-sizes)) | N/A | yes | | `intrinsic` (default) | Scale *down* to fit width of container, up to image size | `1x`, `2x` (based on [imageSizes](#image-sizes)) | N/A | yes |
| `fixed` | Sized to `width` and `height` exactly | `1x`, `2x` (based on [imageSizes](#image-sizes)) | N/A | yes | | `fixed` | Sized to `width` and `height` exactly | `1x`, `2x` (based on [imageSizes](#image-sizes)) | N/A | yes |
| `responsive` | Scale to fit width of container | `640w`, `750w`, ... `2048w`, `3840w` (based on [imageSizes](#image-sizes) and [deviceSizes](#device-sizes)) | `100vw` | yes | | `responsive` | Scale to fit width of container | `640w`, `750w`, ... `2048w`, `3840w` (based on [imageSizes](#image-sizes) and [deviceSizes](#device-sizes)) | `100vw` | yes |
| `fill` | Grow in both X and Y axes to fill container | `640w`, `750w`, ... `2048w`, `3840w` (based on [imageSizes](#image-sizes) and [deviceSizes](#device-sizes)) | `100vw` | yes | | `fill` | Grow in both X and Y axes to fill container | `640w`, `750w`, ... `2048w`, `3840w` (based on [imageSizes](#image-sizes) and [deviceSizes](#device-sizes)) | `100vw` | yes |
| `raw`[\*](#experimental-raw-layout-mode) | Raw `<img>` without styles and native lazy loading | Behaves like `responsive` if the image has the `sizes` prop, and like `fixed` if it does not | optional | no |
- [Demo the `intrinsic` layout (default)](https://image-component.nextjs.gallery/layout-intrinsic) - [Demo the `intrinsic` layout (default)](https://image-component.nextjs.gallery/layout-intrinsic)
- When `intrinsic`, the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports. - When `intrinsic`, the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports.
...@@ -134,7 +133,7 @@ const MyImage = (props) => { ...@@ -134,7 +133,7 @@ const MyImage = (props) => {
A string that provides information about how wide the image will be at different breakpoints. Defaults to `100vw` (the full width of the screen) when using `layout="responsive"` or `layout="fill"`. A string that provides information about how wide the image will be at different breakpoints. Defaults to `100vw` (the full width of the screen) when using `layout="responsive"` or `layout="fill"`.
If you are using `layout="fill"`, `layout="responsive"`, or `layout="raw"`[\*](#experimental-raw-layout-mode) it's important to assign `sizes` for any image that takes up less than the full viewport width. If you are using `layout="fill"` or `layout="responsive"` it's important to assign `sizes` for any image that takes up less than the full viewport width.
For example, when the parent element will constrain the image to always be less than half the viewport width, use `sizes="50vw"`. Without `sizes`, the image will be sent at twice the necessary resolution, decreasing performance. For example, when the parent element will constrain the image to always be less than half the viewport width, use `sizes="50vw"`. Without `sizes`, the image will be sent at twice the necessary resolution, decreasing performance.
...@@ -179,7 +178,7 @@ In some cases, you may need more advanced usage. The `<Image />` component optio ...@@ -179,7 +178,7 @@ In some cases, you may need more advanced usage. The `<Image />` component optio
Allows [passing CSS styles](https://reactjs.org/docs/dom-elements.html#style) to the underlying image element. Allows [passing CSS styles](https://reactjs.org/docs/dom-elements.html#style) to the underlying image element.
Note that all `layout` modes other than `"raw"`[\*](#experimental-raw-layout-mode) apply their own styles to the image element, and these automatic styles take precedence over the `style` prop. Note that all `layout` modes apply their own styles to the image element, and these automatic styles take precedence over the `style` prop.
Also keep in mind that the required `width` and `height` props can interact with your styling. If you use styling to modify an image's `width`, you must set the `height="auto"` style as well, or your image will be distorted. Also keep in mind that the required `width` and `height` props can interact with your styling. If you use styling to modify an image's `width`, you must set the `height="auto"` style as well, or your image will be distorted.
...@@ -554,17 +553,7 @@ module.exports = { ...@@ -554,17 +553,7 @@ module.exports = {
### Experimental "raw" layout mode ### Experimental "raw" layout mode
The image component currently supports an additional `layout="raw"` mode, which renders the image without wrappers or styling. This layout mode is currently an experimental feature, while user feedback is gathered. As there is the possibility of breaking changes to the `layout="raw"` interface, the feature is locked behind an experimental feature flag. If you would like to use the `raw` layout mode, you must add the following to your `next.config.js`: The `layout="raw"` experiment has been moved to a new module. Please use [`next/future/image`](/docs/api-reference/next/future/image.md) instead.
```js
module.exports = {
experimental: {
images: {
layoutRaw: true,
},
},
}
```
### Animated Images ### Animated Images
......
...@@ -18,11 +18,8 @@ import { ImageConfigContext } from '../shared/lib/image-config-context' ...@@ -18,11 +18,8 @@ import { ImageConfigContext } from '../shared/lib/image-config-context'
import { warnOnce } from '../shared/lib/utils' import { warnOnce } from '../shared/lib/utils'
import { normalizePathTrailingSlash } from './normalize-trailing-slash' import { normalizePathTrailingSlash } from './normalize-trailing-slash'
const { const { experimentalRemotePatterns = [], experimentalUnoptimized } =
experimentalLayoutRaw = false, (process.env.__NEXT_IMAGE_OPTS as any) || {}
experimentalRemotePatterns = [],
experimentalUnoptimized,
} = (process.env.__NEXT_IMAGE_OPTS as any) || {}
const configEnv = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete const configEnv = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete
const loadedImageURLs = new Set<string>() const loadedImageURLs = new Set<string>()
const allImgs = new Map< const allImgs = new Map<
...@@ -74,7 +71,6 @@ const VALID_LAYOUT_VALUES = [ ...@@ -74,7 +71,6 @@ const VALID_LAYOUT_VALUES = [
'fixed', 'fixed',
'intrinsic', 'intrinsic',
'responsive', 'responsive',
'raw',
undefined, undefined,
] as const ] as const
type LayoutValue = typeof VALID_LAYOUT_VALUES[number] type LayoutValue = typeof VALID_LAYOUT_VALUES[number]
...@@ -175,10 +171,7 @@ function getWidths( ...@@ -175,10 +171,7 @@ function getWidths(
layout: LayoutValue, layout: LayoutValue,
sizes: string | undefined sizes: string | undefined
): { widths: number[]; kind: 'w' | 'x' } { ): { widths: number[]; kind: 'w' | 'x' } {
if ( if (sizes && (layout === 'fill' || layout === 'responsive')) {
sizes &&
(layout === 'fill' || layout === 'responsive' || layout === 'raw')
) {
// Find all the "vw" percent sizes used in the sizes prop // Find all the "vw" percent sizes used in the sizes prop
const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g
const percentSizes = [] const percentSizes = []
...@@ -333,19 +326,6 @@ function handleLoading( ...@@ -333,19 +326,6 @@ function handleLoading(
onLoadingCompleteRef.current({ naturalWidth, naturalHeight }) onLoadingCompleteRef.current({ naturalWidth, naturalHeight })
} }
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
if (layout === 'raw') {
const heightModified =
img.height.toString() !== img.getAttribute('height')
const widthModified = img.width.toString() !== img.getAttribute('width')
if (
(heightModified && !widthModified) ||
(!heightModified && widthModified)
) {
warnOnce(
`Image with src "${src}" has either width or height modified, but not the other. If you use CSS to change the size of your image, also include the styles 'width: "auto"' or 'height: "auto"' to maintain the aspect ratio.`
)
}
}
if (img.parentElement?.parentElement) { if (img.parentElement?.parentElement) {
const parent = getComputedStyle(img.parentElement.parentElement) const parent = getComputedStyle(img.parentElement.parentElement)
if (!parent.position) { if (!parent.position) {
...@@ -460,11 +440,7 @@ export default function Image({ ...@@ -460,11 +440,7 @@ export default function Image({
unoptimized = true unoptimized = true
isLazy = false isLazy = false
} }
if ( if (typeof window !== 'undefined' && loadedImageURLs.has(src)) {
typeof window !== 'undefined' &&
loadedImageURLs.has(src) &&
layout !== 'raw'
) {
isLazy = false isLazy = false
} }
if (experimentalUnoptimized) { if (experimentalUnoptimized) {
...@@ -478,7 +454,7 @@ export default function Image({ ...@@ -478,7 +454,7 @@ export default function Image({
rootMargin: lazyBoundary || '200px', rootMargin: lazyBoundary || '200px',
disabled: !isLazy, disabled: !isLazy,
}) })
const isVisible = !isLazy || isIntersected || layout === 'raw' const isVisible = !isLazy || isIntersected
const wrapperStyle: JSX.IntrinsicElements['span']['style'] = { const wrapperStyle: JSX.IntrinsicElements['span']['style'] = {
boxSizing: 'border-box', boxSizing: 'border-box',
...@@ -529,9 +505,6 @@ export default function Image({ ...@@ -529,9 +505,6 @@ export default function Image({
objectPosition, objectPosition,
} }
if (process.env.NODE_ENV !== 'production' && layout !== 'raw' && style) {
}
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
if (!src) { if (!src) {
throw new Error( throw new Error(
...@@ -541,17 +514,18 @@ export default function Image({ ...@@ -541,17 +514,18 @@ export default function Image({
) )
} }
if (!VALID_LAYOUT_VALUES.includes(layout)) { if (!VALID_LAYOUT_VALUES.includes(layout)) {
if ((layout as any) === 'raw') {
throw new Error( throw new Error(
`Image with src "${src}" has invalid "layout" property. Provided "${layout}" should be one of ${VALID_LAYOUT_VALUES.map( `The layout="raw" experiment has been moved to a new module. Please import \`next/future/image\` instead.`
String
).join(',')}.`
) )
} }
if (layout === 'raw' && !experimentalLayoutRaw) {
throw new Error( throw new Error(
`The "raw" layout is currently experimental and may be subject to breaking changes. To use layout="raw", include \`experimental: { images: { layoutRaw: true } }\` in your next.config.js file.` `Image with src "${src}" has invalid "layout" property. Provided "${layout}" should be one of ${VALID_LAYOUT_VALUES.map(
String
).join(',')}.`
) )
} }
if ( if (
(typeof widthInt !== 'undefined' && isNaN(widthInt)) || (typeof widthInt !== 'undefined' && isNaN(widthInt)) ||
(typeof heightInt !== 'undefined' && isNaN(heightInt)) (typeof heightInt !== 'undefined' && isNaN(heightInt))
...@@ -577,36 +551,9 @@ export default function Image({ ...@@ -577,36 +551,9 @@ export default function Image({
`Image with src "${src}" has both "priority" and "loading='lazy'" properties. Only one should be used.` `Image with src "${src}" has both "priority" and "loading='lazy'" properties. Only one should be used.`
) )
} }
if (layout === 'raw') { if (sizes && layout !== 'fill' && layout !== 'responsive') {
if (objectFit) {
throw new Error(
`Image with src "${src}" has "layout='raw'" and "objectFit='${objectFit}'". For raw images, these and other styles should be specified using the "style" attribute.`
)
}
if (objectPosition) {
throw new Error(
`Image with src "${src}" has "layout='raw'" and "objectPosition='${objectPosition}'". For raw images, these and other styles should be specified using the "style" attribute.`
)
}
if (lazyRoot) {
throw new Error(
`Image with src "${src}" has "layout='raw'" and "lazyRoot='${lazyRoot}'". For raw images, native lazy loading is used so "lazyRoot" cannot be used.`
)
}
if (lazyBoundary) {
throw new Error(
`Image with src "${src}" has "layout='raw'" and "lazyBoundary='${lazyBoundary}'". For raw images, native lazy loading is used so "lazyBoundary" cannot be used.`
)
}
}
if (
sizes &&
layout !== 'fill' &&
layout !== 'responsive' &&
layout !== 'raw'
) {
warnOnce( warnOnce(
`Image with src "${src}" has "sizes" property but it will be ignored. Only use "sizes" with "layout='fill'", "layout='responsive'", or "layout='raw'` `Image with src "${src}" has "sizes" property but it will be ignored. Only use "sizes" with "layout='fill'" or "layout='responsive'"`
) )
} }
if (placeholder === 'blur') { if (placeholder === 'blur') {
...@@ -655,7 +602,7 @@ export default function Image({ ...@@ -655,7 +602,7 @@ export default function Image({
} }
} }
if (style && layout !== 'raw') { if (style) {
let overwrittenStyles = Object.keys(style).filter( let overwrittenStyles = Object.keys(style).filter(
(key) => key in layoutStyle (key) => key in layoutStyle
) )
...@@ -704,21 +651,14 @@ export default function Image({ ...@@ -704,21 +651,14 @@ export default function Image({
} }
} }
} }
const imgStyle = Object.assign({}, style, layout === 'raw' ? {} : layoutStyle) const imgStyle = Object.assign({}, style, layoutStyle)
const svgBlurPlaceholder = `url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http%3A//www.w3.org/2000/svg' xmlns%3Axlink='http%3A//www.w3.org/1999/xlink' viewBox='0 0 ${widthInt} ${heightInt}'%3E%3Cfilter id='b' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='50'%3E%3C/feGaussianBlur%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1'%3E%3C/feFuncA%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23b)' x='0' y='0' height='100%25' width='100%25' href='${blurDataURL}'%3E%3C/image%3E%3C/svg%3E");`
const blurStyle = const blurStyle =
placeholder === 'blur' && !blurComplete placeholder === 'blur' && !blurComplete
? { ? {
backgroundSize: objectFit || 'cover', backgroundSize: objectFit || 'cover',
backgroundPosition: objectPosition || '0% 0%', backgroundPosition: objectPosition || '0% 0%',
...(layout === 'raw' && blurDataURL?.startsWith('data:image')
? {
backgroundImage: svgBlurPlaceholder,
}
: {
filter: 'blur(20px)', filter: 'blur(20px)',
backgroundImage: `url("${blurDataURL}")`, backgroundImage: `url("${blurDataURL}")`,
}),
} }
: {} : {}
if (layout === 'fill') { if (layout === 'fill') {
...@@ -852,9 +792,7 @@ export default function Image({ ...@@ -852,9 +792,7 @@ export default function Image({
} }
return ( return (
<> <>
{layout === 'raw' ? ( {
<ImageElement {...imgElementArgs} />
) : (
<span style={wrapperStyle}> <span style={wrapperStyle}>
{hasSizer ? ( {hasSizer ? (
<span style={sizerStyle}> <span style={sizerStyle}>
...@@ -880,7 +818,7 @@ export default function Image({ ...@@ -880,7 +818,7 @@ export default function Image({
) : null} ) : null}
<ImageElement {...imgElementArgs} /> <ImageElement {...imgElementArgs} />
</span> </span>
)} }
{priority ? ( {priority ? (
// Note how we omit the `href` attribute, as it would only be relevant // Note how we omit the `href` attribute, as it would only be relevant
// for browsers that do not support `imagesrcset`, and in those cases // for browsers that do not support `imagesrcset`, and in those cases
...@@ -937,12 +875,9 @@ const ImageElement = ({ ...@@ -937,12 +875,9 @@ const ImageElement = ({
<img <img
{...rest} {...rest}
{...imgAttributes} {...imgAttributes}
{...(layout === 'raw' ? { height: heightInt, width: widthInt } : {})}
decoding="async" decoding="async"
data-nimg={layout} data-nimg={layout}
className={className} className={className}
// @ts-ignore - TODO: upgrade to `@types/react@17`
loading={layout === 'raw' ? loading : undefined}
style={{ ...imgStyle, ...blurStyle }} style={{ ...imgStyle, ...blurStyle }}
ref={useCallback( ref={useCallback(
(img: ImgElementWithDataProp) => { (img: ImgElementWithDataProp) => {
...@@ -1005,9 +940,6 @@ const ImageElement = ({ ...@@ -1005,9 +940,6 @@ const ImageElement = ({
sizes: noscriptSizes, sizes: noscriptSizes,
loader, loader,
})} })}
{...(layout === 'raw'
? { height: heightInt, width: widthInt }
: {})}
decoding="async" decoding="async"
data-nimg={layout} data-nimg={layout}
style={imgStyle} style={imgStyle}
......
...@@ -15,17 +15,6 @@ export default function Page() { ...@@ -15,17 +15,6 @@ export default function Page() {
blurDataURL="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E" blurDataURL="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E"
/> />
<Image
priority
id="blurry-placeholder-raw"
src="/test.ico"
width="400"
height="400"
layout="raw"
placeholder="blur"
blurDataURL="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E"
/>
<Image <Image
priority priority
id="blurry-placeholder-tall-centered" id="blurry-placeholder-tall-centered"
......
import React from 'react'
import Image from 'next/image'
const Page = () => {
return (
<div>
<Image
id="invalid-raw-lazy-boundary"
layout="raw"
src="/test.jpg"
width={200}
height={200}
lazyBoundary="500px"
/>
</div>
)
}
export default Page
import React from 'react'
import Image from 'next/image'
import testJPG from '../public/test.jpg'
import testPNG from '../public/test.png'
const Page = () => {
return (
<div id="container">
<h1>Layout Raw with Placeholder Blur</h1>
<p>Scroll down...</p>
<div style={{ height: '1000vh' }} />
<Image id="raw1" layout="raw" placeholder="blur" src={testJPG} />
<div style={{ height: '1000vh' }} />
<Image
id="raw2"
layout="raw"
placeholder="blur"
src={testPNG}
sizes="50vw"
/>
<footer>Footer</footer>
</div>
)
}
export default Page
import React from 'react'
import Image from 'next/image'
const Page = () => {
return (
<div>
<p>Layout Raw</p>
<div id="image-container1">
<Image
id="raw1"
src="/wide.png"
width="1200"
height="700"
layout="raw"
loading="eager"
></Image>
</div>
<div id="image-container2">
<Image
id="raw2"
src="/wide.png"
width="1200"
height="700"
style={{
paddingLeft: '4rem',
width: '100%',
objectPosition: '30% 30%',
}}
layout="raw"
sizes="50vh"
></Image>
</div>
<div id="image-container3">
<Image
id="raw3"
src="/test.png"
width="400"
height="400"
layout="raw"
loading="eager"
></Image>
</div>
<div id="image-container4">
<Image
id="raw4"
src="/test.png"
width="400"
height="400"
layout="raw"
loading="eager"
style={{ width: '50%', height: 'auto' }}
></Image>
</div>
</div>
)
}
export default Page
...@@ -85,15 +85,6 @@ const Page = () => { ...@@ -85,15 +85,6 @@ const Page = () => {
setIdToCount={setIdToCount} setIdToCount={setIdToCount}
/> />
<ImageWithMessage
id="9"
src={require('../public/test.png')}
placeholder="blur"
layout="raw"
idToCount={idToCount}
setIdToCount={setIdToCount}
/>
<button id="toggle" onClick={() => setClicked(!clicked)}> <button id="toggle" onClick={() => setClicked(!clicked)}>
Toggle Toggle
</button> </button>
......
...@@ -35,14 +35,6 @@ const Page = () => { ...@@ -35,14 +35,6 @@ const Page = () => {
height="700" height="700"
layout="responsive" layout="responsive"
/> />
<Image
priority
id="raw1"
src="/test.webp"
width="1200"
height="700"
layout="raw"
/>
<p id="stubtext">This is the priority page</p> <p id="stubtext">This is the priority page</p>
</div> </div>
) )
......
...@@ -23,12 +23,6 @@ const Page = () => { ...@@ -23,12 +23,6 @@ const Page = () => {
layout="fixed" layout="fixed"
placeholder="blur" placeholder="blur"
/> />
<Image
id="basic-static-raw"
src={testImg}
layout="raw"
placeholder="blur"
/>
<TallImage /> <TallImage />
<Image <Image
id="defined-size-static" id="defined-size-static"
......
...@@ -23,15 +23,6 @@ const Page = () => { ...@@ -23,15 +23,6 @@ const Page = () => {
style={{ width: '10px', borderRadius: '10px', margin: '15px' }} style={{ width: '10px', borderRadius: '10px', margin: '15px' }}
loading="eager" loading="eager"
/> />
<Image
layout="raw"
id="with-overlapping-styles-raw"
src="/test.webp"
width={400}
height={400}
style={{ width: '10px', borderRadius: '10px', margin: '15px' }}
loading="eager"
/>
<Image <Image
layout="responsive" layout="responsive"
id="without-styles-responsive" id="without-styles-responsive"
...@@ -40,14 +31,6 @@ const Page = () => { ...@@ -40,14 +31,6 @@ const Page = () => {
height={400} height={400}
loading="eager" loading="eager"
/> />
<Image
layout="raw"
id="without-styles-raw"
src="/test.webp"
width={400}
height={400}
loading="eager"
/>
</div> </div>
) )
} }
......
...@@ -69,11 +69,6 @@ const runTests = () => { ...@@ -69,11 +69,6 @@ const runTests = () => {
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&quot;)"` `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&quot;)"`
) )
}) })
it('Should add a blur to a statically imported image in "raw" mode', async () => {
expect(html).toContain(
`style="background-size:cover;background-position:0% 0%;background-image:url(&quot;data:image/svg+xml;charset=utf-8,%3Csvg xmlns=&#x27;http%3A//www.w3.org/2000/svg&#x27; xmlns%3Axlink=&#x27;http%3A//www.w3.org/1999/xlink&#x27; viewBox=&#x27;0 0 400 300&#x27;%3E%3Cfilter id=&#x27;b&#x27; color-interpolation-filters=&#x27;sRGB&#x27;%3E%3CfeGaussianBlur stdDeviation=&#x27;50&#x27;%3E%3C/feGaussianBlur%3E%3CfeComponentTransfer%3E%3CfeFuncA type=&#x27;discrete&#x27; tableValues=&#x27;1 1&#x27;%3E%3C/feFuncA%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter=&#x27;url(%23b)&#x27; x=&#x27;0&#x27; y=&#x27;0&#x27; height=&#x27;100%25&#x27; width=&#x27;100%25&#x27; href=&#x27;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&#x27;%3E%3C/image%3E%3C/svg%3E&quot;);`
)
})
it('Should add a blur placeholder to statically imported png', async () => { it('Should add a blur placeholder to statically imported png', async () => {
expect(html).toContain( expect(html).toContain(
`style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAOklEQVR42iWGsQkAIBDE0iuIdiLOJjiGIzjiL/Meb4okiNYIlLjK3hJMzCQG1/0qmXXOUkjAV+m9wAMe3QiV6Ne8VgAAAABJRU5ErkJggg==&quot;)` `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;background-size:cover;background-position:0% 0%;filter:blur(20px);background-image:url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAOklEQVR42iWGsQkAIBDE0iuIdiLOJjiGIzjiL/Meb4okiNYIlLjK3hJMzCQG1/0qmXXOUkjAV+m9wAMe3QiV6Ne8VgAAAABJRU5ErkJggg==&quot;)`
......
...@@ -18,7 +18,6 @@ const Page = () => { ...@@ -18,7 +18,6 @@ const Page = () => {
<div> <div>
<h1 id="page-header">Static Image</h1> <h1 id="page-header">Static Image</h1>
<Image id="basic-static" src={testImg} placeholder="blur" /> <Image id="basic-static" src={testImg} placeholder="blur" />
<Image id="basic-static-raw" src={testImg} placeholder="blur" />
<TallImage /> <TallImage />
<Image id="defined-size-static" src={testPNG} height="150" width="150" /> <Image id="defined-size-static" src={testPNG} height="150" width="150" />
<Image id="require-static" src={require('../public/foo/test-rect.jpg')} /> <Image id="require-static" src={require('../public/foo/test-rect.jpg')} />
......
...@@ -63,7 +63,7 @@ const runTests = () => { ...@@ -63,7 +63,7 @@ const runTests = () => {
it('Should allow provided width and height to override intrinsic', async () => { it('Should allow provided width and height to override intrinsic', async () => {
expect(html).toContain('width="150" height="150"') expect(html).toContain('width="150" height="150"')
}) })
it('Should add a blur to a statically imported image in "raw" mode', async () => { it('Should add a blur to a statically imported image', async () => {
expect(html).toContain( expect(html).toContain(
`style="background-size:cover;background-position:0% 0%;background-image:url(&quot;data:image/svg+xml;charset=utf-8,%3Csvg xmlns=&#x27;http%3A//www.w3.org/2000/svg&#x27; xmlns%3Axlink=&#x27;http%3A//www.w3.org/1999/xlink&#x27; viewBox=&#x27;0 0 400 300&#x27;%3E%3Cfilter id=&#x27;b&#x27; color-interpolation-filters=&#x27;sRGB&#x27;%3E%3CfeGaussianBlur stdDeviation=&#x27;50&#x27;%3E%3C/feGaussianBlur%3E%3CfeComponentTransfer%3E%3CfeFuncA type=&#x27;discrete&#x27; tableValues=&#x27;1 1&#x27;%3E%3C/feFuncA%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter=&#x27;url(%23b)&#x27; x=&#x27;0&#x27; y=&#x27;0&#x27; height=&#x27;100%25&#x27; width=&#x27;100%25&#x27; href=&#x27;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&#x27;%3E%3C/image%3E%3C/svg%3E&quot;);` `style="background-size:cover;background-position:0% 0%;background-image:url(&quot;data:image/svg+xml;charset=utf-8,%3Csvg xmlns=&#x27;http%3A//www.w3.org/2000/svg&#x27; xmlns%3Axlink=&#x27;http%3A//www.w3.org/1999/xlink&#x27; viewBox=&#x27;0 0 400 300&#x27;%3E%3Cfilter id=&#x27;b&#x27; color-interpolation-filters=&#x27;sRGB&#x27;%3E%3CfeGaussianBlur stdDeviation=&#x27;50&#x27;%3E%3C/feGaussianBlur%3E%3CfeComponentTransfer%3E%3CfeFuncA type=&#x27;discrete&#x27; tableValues=&#x27;1 1&#x27;%3E%3C/feFuncA%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter=&#x27;url(%23b)&#x27; x=&#x27;0&#x27; y=&#x27;0&#x27; height=&#x27;100%25&#x27; width=&#x27;100%25&#x27; href=&#x27;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z&#x27;%3E%3C/image%3E%3C/svg%3E&quot;);`
) )
......
...@@ -7,12 +7,12 @@ import testPNG from '../public/test.png' ...@@ -7,12 +7,12 @@ import testPNG from '../public/test.png'
const Page = () => { const Page = () => {
return ( return (
<div id="container"> <div id="container">
<h1>Layout Raw with Placeholder Blur</h1> <h1>Placeholder Blur</h1>
<p>Scroll down...</p> <p>Scroll down...</p>
<div style={{ height: '1000vh' }} /> <div style={{ height: '1000vh' }} />
<Image id="raw1" placeholder="blur" src={testJPG} /> <Image id="blur1" placeholder="blur" src={testJPG} />
<div style={{ height: '1000vh' }} /> <div style={{ height: '1000vh' }} />
<Image id="raw2" placeholder="blur" src={testPNG} sizes="50vw" /> <Image id="blur2" placeholder="blur" src={testPNG} sizes="50vw" />
<footer>Footer</footer> <footer>Footer</footer>
</div> </div>
) )
......
...@@ -35,7 +35,6 @@ const Page = () => { ...@@ -35,7 +35,6 @@ const Page = () => {
height="700" height="700"
sizes="100vw" sizes="100vw"
/> />
<Image priority id="raw1" src="/test.webp" width="1200" height="700" />
<p id="stubtext">This is the priority page</p> <p id="stubtext">This is the priority page</p>
</div> </div>
) )
......
...@@ -18,7 +18,6 @@ const Page = () => { ...@@ -18,7 +18,6 @@ const Page = () => {
<div> <div>
<h1 id="page-header">Static Image</h1> <h1 id="page-header">Static Image</h1>
<Image id="basic-static" src={testImg} placeholder="blur" /> <Image id="basic-static" src={testImg} placeholder="blur" />
<Image id="basic-static-raw" src={testImg} placeholder="blur" />
<TallImage /> <TallImage />
<Image id="defined-size-static" src={testPNG} height="150" width="150" /> <Image id="defined-size-static" src={testPNG} height="150" width="150" />
<Image id="require-static" src={require('../public/foo/test-rect.jpg')} /> <Image id="require-static" src={require('../public/foo/test-rect.jpg')} />
......
...@@ -14,7 +14,7 @@ const Page = () => { ...@@ -14,7 +14,7 @@ const Page = () => {
loading="eager" loading="eager"
/> />
<Image <Image
id="with-overlapping-styles-intrinsic" id="with-overlapping-styles"
src="/test.jpg" src="/test.jpg"
width={400} width={400}
height={400} height={400}
...@@ -22,22 +22,7 @@ const Page = () => { ...@@ -22,22 +22,7 @@ const Page = () => {
loading="eager" loading="eager"
/> />
<Image <Image
id="with-overlapping-styles-raw" id="without-styles"
src="/test.webp"
width={400}
height={400}
style={{ width: '10px', borderRadius: '10px', margin: '15px' }}
loading="eager"
/>
<Image
id="without-styles-responsive"
src="/test.webp"
width={400}
height={400}
loading="eager"
/>
<Image
id="without-styles-raw"
src="/test.webp" src="/test.webp"
width={400} width={400}
height={400} height={400}
......
...@@ -4,19 +4,19 @@ import Image from 'next/future/image' ...@@ -4,19 +4,19 @@ import Image from 'next/future/image'
const Page = () => { const Page = () => {
return ( return (
<div> <div>
<p>Layout Raw</p> <p>Wrapper Div</p>
<div id="image-container1"> <div id="image-container1">
<Image <Image
id="raw1" id="img1"
src="/wide.png" src="/wide.png"
width="1200" width="1200"
height="700" height="700"
loading="eager" loading="eager"
></Image> />
</div> </div>
<div id="image-container2"> <div id="image-container2">
<Image <Image
id="raw2" id="img2"
src="/wide.png" src="/wide.png"
width="1200" width="1200"
height="700" height="700"
...@@ -26,26 +26,26 @@ const Page = () => { ...@@ -26,26 +26,26 @@ const Page = () => {
objectPosition: '30% 30%', objectPosition: '30% 30%',
}} }}
sizes="50vh" sizes="50vh"
></Image> />
</div> </div>
<div id="image-container3"> <div id="image-container3">
<Image <Image
id="raw3" id="img3"
src="/test.png" src="/test.png"
width="400" width="400"
height="400" height="400"
loading="eager" loading="eager"
></Image> />
</div> </div>
<div id="image-container4"> <div id="image-container4">
<Image <Image
id="raw4" id="img4"
src="/test.png" src="/test.png"
width="400" width="400"
height="400" height="400"
loading="eager" loading="eager"
style={{ width: '50%', height: 'auto' }} style={{ width: '50%', height: 'auto' }}
></Image> />
</div> </div>
</div> </div>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment