prefix
stringlengths
512
512
suffix
stringlengths
256
256
middle
stringlengths
14
229
meta
dict
from 'e2e-utils' const isAdapterTest = Boolean(process.env.NEXT_ENABLE_ADAPTER) describe('not-found-with-pages-i18n', () => { const { next, isNextStart, isNextDeploy } = nextTestSetup({ files: __dirname, }) if (isNextStart) { it('should write all locales to the pages manifest', async () => { cons...
SKIP_TEST_FOR_BUILDER = isNextDeploy ? !isAdapterTest : false if (!SKIP_TEST_FOR_BUILDER) { it.each(['/app-dir/foo', '/foo'])( 'should prefer the app router 404 over the pages router 404 when both are present - browser %s', async (s) =>
n/404']).toBe('pages/404.html') expect(pagesManifest['/en-GB/404']).toBe('pages/404.html') }) } // When using the builder, pages router is incorrectly preferred. This is already fixed when using the adapter const
{ "filepath": "test/e2e/app-dir/not-found-with-pages-i18n/not-found-with-pages.test.ts", "language": "typescript", "file_size": 1695, "cut_index": 537, "middle_length": 229 }
rom 'e2e-utils' import { findPort } from 'next-test-utils' import http from 'node:http' describe('ppr-unstable-cache', () => { if (isNextDeploy) { it.skip('should not run in deploy mode', () => {}) return } if (isNextDev) { it.skip('should not run in dev mode', () => {}) return } const { ne...
const cache = new URL(req.url, 'http://n').searchParams.get('cache') if (!cache) throw new Error('No cache key') const random = Math.floor(Math.random() * 1000).toString() const data = cache + ':' + random generatio
ver = null } }) it('should not cache inner fetch calls', async () => { let generations: string[] = [] server = http.createServer(async (req, res) => { try { if (!req.url) throw new Error('No URL')
{ "filepath": "test/e2e/app-dir/ppr-unstable-cache/ppr-unstable-cache.test.ts", "language": "typescript", "file_size": 2945, "cut_index": 563, "middle_length": 229 }
* as React from 'react' import * as react from 'library-with-exports/react' import * as serverFavoringBrowser from 'library-with-exports/server-favoring-browser' import * as serverFavoringEdge from 'library-with-exports/server-favoring-edge' export const config = { runtime: 'experimental-edge', } let server = { ...
react: react.condition, serverFavoringBrowser: serverFavoringBrowser.condition, serverFavoringEdge: serverFavoringEdge.condition, }) }, []) return ( <output aria-busy={client === null}> {client === null ? ( <pre d
se( document.querySelector('[data-testid="server"]')!.textContent! ) } export default function Page() { const [client, setClient] = React.useState<unknown | null>(null) React.useLayoutEffect(() => { setClient({
{ "filepath": "test/e2e/import-conditions/pages/pages/edge-page.tsx", "language": "tsx", "file_size": 1221, "cut_index": 518, "middle_length": 229 }
lient' import React from 'react' import Image from 'next/image' const Page = () => { return ( <div> <h1>Warn for this loader that doesnt use width</h1> <Image id="no-width" src="/test.png" width={100} height={100} loader={({ src }) => `${src}`} /> <...
f" width={100} height={100} loader={({ src, width }) => `https://example.vercel.sh${src}?width=${width * 2}` } /> <Image id="width-querystring-size" src="/test.tiff" width={100}
"width-querystring-w" src="/test.webp" width={100} height={100} loader={({ src, width }) => `${src}?w=${width / 2}`} /> <Image id="width-querystring-width" src="/test.gi
{ "filepath": "test/e2e/next-image-new/app-dir/app/invalid-loader/page.js", "language": "javascript", "file_size": 1177, "cut_index": 518, "middle_length": 229 }
from 'next/image' const shimmer = `data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImciPgogICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjMzMzIiBvZ...
FzIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgIC8+Cjwvc3ZnPg==` export default function Page() { return ( <div> <p>Data URL Placeholder</p> <Image priority id="data-url-placeholder-raw" src="/test.ico" width="400
3Qgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIGZpbGw9IiMzMzMiIC8+CiAgPHJlY3QgaWQ9InIiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIiBmaWxsPSJ1cmwoI2cpIiAvPgogIDxhbmltYXRlIHhsaW5rOmhyZWY9IiNyIiBhdHRyaWJ1dGVOYW1lPSJ4IiBmcm9tPSItMjAwIiB0bz0iMjAwIiBkdXI9Ij
{ "filepath": "test/e2e/next-image-new/app-dir/app/data-url-placeholder/page.js", "language": "javascript", "file_size": 1336, "cut_index": 524, "middle_length": 229 }
React from 'react' import Image from 'next/image' export default function Page() { return ( <div style={{ position: 'absolute', width: '200px', height: '200px' }}> <p>Data Url With Fill And Sizes</p> <Image src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http%3A//www.w3.org/2000/svg' %3E...
KSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAAgDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAL/xAAeEAABBAIDAQAAAAAAAAAAAAACAAEDBAUhBhRRsf/EABQBAQAAAAAAAAAAAAAAAAAAAAL/xAAWEQEBAQAAAAAAAAAAAAAAAAABAgD/
%%3C/filter%3E%3Cimage filter='url(%23b)' x='0' y='0' height='100%' width='100%' preserveAspectRatio='none' href='data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUo
{ "filepath": "test/e2e/next-image-new/app-dir/app/data-url-with-fill-and-sizes/page.js", "language": "javascript", "file_size": 1160, "cut_index": 518, "middle_length": 229 }
eact from 'react' import Image from 'next/image' import test from '../../public/test.jpg' const Page = () => { return ( <div> <h1>Fill Mode</h1> <div id="image-container-1" style={{ height: '300px', width: '300px', position: 'relative', overflo...
ition: 'relative', overflow: 'hidden', }} > <Image id="fill-image-blur" src={test} sizes="300px" placeholder="blur" fill /> </div> </div> ) } export defa
ht: '300px', width: '300px', pos
{ "filepath": "test/e2e/next-image-new/app-dir/app/fill/page.js", "language": "javascript", "file_size": 837, "cut_index": 520, "middle_length": 52 }
/image' import testJPG from '../../public/test.jpg' import testPNG from '../../public/test.png' import testWEBP from '../../public/test.webp' import testAVIF from '../../public/test.avif' import testSVG from '../../public/test.svg' import testGIF from '../../public/test.gif' import testBMP from '../../public/test.bmp'...
xml;base64,Cjxzdmcgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImciPgogICAgICA8c3RvcCBzdG9wLWNvbG9yP
import TallImage from '../../components/TallImage' const blurDataURL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNM/s/wBwAFjwJgf8HDLgAAAABJRU5ErkJggg==' const shimmer = `data:image/svg+
{ "filepath": "test/e2e/next-image-new/app-dir/app/static-img/page.js", "language": "javascript", "file_size": 4712, "cut_index": 614, "middle_length": 229 }
import Image from 'next/image' const Page = () => { return ( <div> <p>Priority Page</p> <Image priority id="basic-image" alt="basic-image" src="/test.jpg" width="400" height="400" ></Image> <Image priority id="basic-image-cr...
ading="eager" id="load-eager" alt="load-eager" src="/test.png" width="200" height="200" ></Image> <Image priority id="responsive1" alt="responsive1" src="/wide.png"
iority id="basic-image-referrerpolicy" alt="basic-image-referrerpolicy" src="/test.png" width="400" height="400" referrerPolicy="no-referrer" ></Image> <Image lo
{ "filepath": "test/e2e/next-image-new/app-dir/app/priority/page.js", "language": "javascript", "file_size": 1705, "cut_index": 537, "middle_length": 229 }
() => { return ( <div> <h1>Fill Mode</h1> <div id="image-container-1" style={{ height: '300px', width: '300px', position: 'relative', overflow: 'hidden', }} > <Image id="fill-image-1" src="/wide.png" fill /> </div> ...
<Image id="fill-image-3" src="/wide.png" fill /> </div> <div id="image-container-4" style={{ position: 'relative', width: '30vw', height: '30vw' }} > <Image id="fill-image-4" src="/test.png" sizes="100vw" fi
, overflow: 'hidden', }} >
{ "filepath": "test/e2e/next-image-new/app-dir/app/fill-warnings/page.js", "language": "javascript", "file_size": 947, "cut_index": 582, "middle_length": 52 }
t Image from 'next/image' const Page = () => { const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) const red = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mO8ysv7HwAEngHwC+JqOgAAAABJRU5ErkJggg==' return ( <div> <h1>Tes...
../public/test.png') : red} placeholder={clicked ? 'blur' : 'empty'} width="256" height="256" idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="3" src={clicked ?
src={clicked ? '/test.jpg' : red} width="128" height="128" idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="2" src={clicked ? require('../
{ "filepath": "test/e2e/next-image-new/app-dir/app/on-load/page.js", "language": "javascript", "file_size": 2395, "cut_index": 563, "middle_length": 229 }
from 'react' import Image from 'next/image' // We don't use a static import intentionally const blurDataURL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAAAAABd+vKJAAAANklEQVR42mNg4GRwdWBgZ2BgUGI4dYhBmYFBgiHy308PBlEGKYbr//9fYJBlYDBYv3nzGkUGANGMDBq2MCnBAAAAAElFTkSuQmCC' export default function Page() {...
isplay: 'flex', minHeight: '30vh' }}> <Image fill alt="alt" src="/wide.png" placeholder="blur" blurDataURL={blurDataURL} id="fit-contain" style={{ objectFit: 'contain' }}
lt" src="/wide.png" placeholder="blur" blurDataURL={blurDataURL} id="fit-cover" style={{ objectFit: 'cover' }} /> </div> <div style={{ position: 'relative', d
{ "filepath": "test/e2e/next-image-new/app-dir/app/fill-blur/page.js", "language": "javascript", "file_size": 1351, "cut_index": 524, "middle_length": 229 }
hrow build error when import statement is used with missing file', async () => { await next.patchFile( 'pages/static-img.js', (content) => content.replace( '../public/foo/test-rect.jpg', '../public/foo/test-rect-broken.jpg' ), async () => { const { cliOu...
files: __dirname, skipDeployment: true, disableAutoSkewProtection: true, }) if (skipped) return let browser: Playwright let $: ReturnType<typeof cheerio.load> beforeAll(async () => { const html = await next.render('/static-img')
pages/static-img.js') expect(cliOutput).not.toContain('Import trace for requested module') } ) }) }) describe('Static Image Component Tests', () => { const { next, isTurbopack, skipped } = nextTestSetup({
{ "filepath": "test/e2e/next-image-new/default/default-static.test.ts", "language": "typescript", "file_size": 15764, "cut_index": 921, "middle_length": 229 }
referrerpolicy, }) } expect( entries.find( (item) => item.imagesrcset === `/_next/image?url=%2Ftest.webp&w=640&q=75${dpl} 1x, /_next/image?url=%2Ftest.webp&w=828&q=75${dpl} 2x` ) ).toEqual({ fetchpriority: '', imagesizes: '', imagesrcset...
28w, /_next/image?url=%2Fwide.png&w=1080&q=75${dpl} 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75${dpl} 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75${dpl} 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75${dpl} 2048w, /_next/image?url=%2Fwide.png&w=3840
entries.find( (item) => item.imagesrcset === `/_next/image?url=%2Fwide.png&w=640&q=75${dpl} 640w, /_next/image?url=%2Fwide.png&w=750&q=75${dpl} 750w, /_next/image?url=%2Fwide.png&w=828&q=75${dpl} 8
{ "filepath": "test/e2e/next-image-new/default/default.test.ts", "language": "typescript", "file_size": 73647, "cut_index": 3790, "middle_length": 229 }
port React from 'react' import Image from 'next/image' export default function Page() { return ( <div> <p>Blurry Placeholder</p> <Image priority id="blurry-placeholder-raw" src="/test.ico" width="400" height="400" placeholder="blur" blurDataURL...
src="/test.bmp" width="400" height="400" placeholder="blur" blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mO0/8/wBwAE/wI85bEJ6gAAAABJRU5ErkJggg==" /> </div> )
<Image id="blurry-placeholder-with-lazy"
{ "filepath": "test/e2e/next-image-new/default/pages/blurry-placeholder.js", "language": "javascript", "file_size": 824, "cut_index": 514, "middle_length": 52 }
from 'next/image' const shimmer = `data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImciPgogICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjMzMzIiBvZ...
FzIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgIC8+Cjwvc3ZnPg==` export default function Page() { return ( <div> <p>Data URL Placeholder</p> <Image priority id="data-url-placeholder-raw" src="/test.ico" width="400
3Qgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIGZpbGw9IiMzMzMiIC8+CiAgPHJlY3QgaWQ9InIiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIiBmaWxsPSJ1cmwoI2cpIiAvPgogIDxhbmltYXRlIHhsaW5rOmhyZWY9IiNyIiBhdHRyaWJ1dGVOYW1lPSJ4IiBmcm9tPSItMjAwIiB0bz0iMjAwIiBkdXI9Ij
{ "filepath": "test/e2e/next-image-new/default/pages/data-url-placeholder.js", "language": "javascript", "file_size": 1306, "cut_index": 524, "middle_length": 229 }
React from 'react' import Image from 'next/image' export default function Page() { return ( <div style={{ position: 'absolute', width: '200px', height: '200px' }}> <p>Data Url With Fill And Sizes</p> <Image src="data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http%3A//www.w3.org/2000/svg' %3E...
KSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAAgDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAL/xAAeEAABBAIDAQAAAAAAAAAAAAACAAEDBAUhBhRRsf/EABQBAQAAAAAAAAAAAAAAAAAAAAL/xAAWEQEBAQAAAAAAAAAAAAAAAAABAgD/
%%3C/filter%3E%3Cimage filter='url(%23b)' x='0' y='0' height='100%' width='100%' preserveAspectRatio='none' href='data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUo
{ "filepath": "test/e2e/next-image-new/default/pages/data-url-with-fill-and-sizes.js", "language": "javascript", "file_size": 1160, "cut_index": 518, "middle_length": 229 }
from 'react' import Image from 'next/image' // We don't use a static import intentionally const blurDataURL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAAAAABd+vKJAAAANklEQVR42mNg4GRwdWBgZ2BgUGI4dYhBmYFBgiHy308PBlEGKYbr//9fYJBlYDBYv3nzGkUGANGMDBq2MCnBAAAAAElFTkSuQmCC' export default function Page() {...
isplay: 'flex', minHeight: '30vh' }}> <Image fill alt="alt" src="/wide.png" placeholder="blur" blurDataURL={blurDataURL} id="fit-contain" style={{ objectFit: 'contain' }}
lt" src="/wide.png" placeholder="blur" blurDataURL={blurDataURL} id="fit-cover" style={{ objectFit: 'cover' }} /> </div> <div style={{ position: 'relative', d
{ "filepath": "test/e2e/next-image-new/default/pages/fill-blur.js", "language": "javascript", "file_size": 1351, "cut_index": 524, "middle_length": 229 }
mage' // We don't use a static import intentionally const shimmer = `data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImciPgogICAgICA8...
m9tPSItMjAwIiB0bz0iMjAwIiBkdXI9IjFzIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgIC8+Cjwvc3ZnPg==` export default function Page() { return ( <> <p>Image with fill with Data URL placeholder</p> <div style={{ position: 'relative', display: 'flex', m
cmFkaWVudD4KICA8L2RlZnM+CiAgPHJlY3Qgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIGZpbGw9IiMzMzMiIC8+CiAgPHJlY3QgaWQ9InIiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIiBmaWxsPSJ1cmwoI2cpIiAvPgogIDxhbmltYXRlIHhsaW5rOmhyZWY9IiNyIiBhdHRyaWJ1dGVOYW1lPSJ4IiBmc
{ "filepath": "test/e2e/next-image-new/default/pages/fill-data-url-placeholder.js", "language": "javascript", "file_size": 1880, "cut_index": 537, "middle_length": 229 }
() => { return ( <div> <h1>Fill Mode</h1> <div id="image-container-1" style={{ height: '300px', width: '300px', position: 'relative', overflow: 'hidden', }} > <Image id="fill-image-1" src="/wide.png" fill /> </div> ...
<Image id="fill-image-3" src="/wide.png" fill /> </div> <div id="image-container-4" style={{ position: 'relative', width: '30vw', height: '30vw' }} > <Image id="fill-image-4" src="/test.png" sizes="100vw" fi
, overflow: 'hidden', }} >
{ "filepath": "test/e2e/next-image-new/default/pages/fill-warnings.js", "language": "javascript", "file_size": 947, "cut_index": 582, "middle_length": 52 }
t from 'react' import Image from 'next/image' import test from '../public/test.jpg' const Page = () => { return ( <div> <h1>Fill Mode</h1> <div id="image-container-1" style={{ height: '300px', width: '300px', position: 'relative', overflow: 'hi...
'relative', overflow: 'hidden', }} > <Image id="fill-image-blur" src={test} sizes="300px" placeholder="blur" fill /> </div> </div> ) } export default Pa
00px', width: '300px', position:
{ "filepath": "test/e2e/next-image-new/default/pages/fill.js", "language": "javascript", "file_size": 834, "cut_index": 523, "middle_length": 52 }
React from 'react' import Image from 'next/image' const Page = () => { return ( <div> <h1>Warn for this loader that doesnt use width</h1> <Image id="no-width" src="/test.png" width={100} height={100} loader={({ src }) => `${src}`} /> <Image ...
dth={100} height={100} loader={({ src, width }) => `https://example.vercel.sh${src}?width=${width * 2}` } /> <Image id="width-querystring-size" src="/test.tiff" width={100} heigh
tring-w" src="/test.webp" width={100} height={100} loader={({ src, width }) => `${src}?w=${width / 2}`} /> <Image id="width-querystring-width" src="/test.gif" wi
{ "filepath": "test/e2e/next-image-new/default/pages/invalid-loader.js", "language": "javascript", "file_size": 1164, "cut_index": 518, "middle_length": 229 }
ort { useState } from 'react' import Image from 'next/image' const Page = () => { const [clicked, setClicked] = useState(false) return ( <div> <h1>Test onError</h1> <p> If error occurred while loading image, native onError should be called. </p> <button id="toggle" onClick={() ...
{id}`) return ( <> <div className="wrap"> <Image id={`img${id}`} onError={(e) => { setMsg(`error occurred while loading ${e.target.id}`) }} {...props} /> </div> <p
? '/404.jpg' : '/test.jpg'} width="200" height="200" /> <div id="footer" /> </div> ) } function ImageWithMessage({ id, ...props }) { const [msg, setMsg] = useState(`no error occurred for img$
{ "filepath": "test/e2e/next-image-new/default/pages/on-error.js", "language": "javascript", "file_size": 1075, "cut_index": 515, "middle_length": 229 }
'next/image' const Page = () => { const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) const red = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mO8ysv7HwAEngHwC+JqOgAAAABJRU5ErkJggg==' return ( <div> <h1>Test onLoad</h1>...
ng') : red} placeholder={clicked ? 'blur' : 'empty'} width="256" height="256" idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="3" src={clicked ? '/test.svg' : re
ked ? '/test.jpg' : red} width="128" height="128" idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="2" src={clicked ? require('../public/test.p
{ "filepath": "test/e2e/next-image-new/default/pages/on-load.js", "language": "javascript", "file_size": 2379, "cut_index": 563, "middle_length": 229 }
te to count each image load callback const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) return ( <div> <h1>On Loading Complete Test</h1> <ImageWithMessage id="1" src="/test.jpg" width="128" height="128" idToCount={i...
> <ImageWithMessage id="4" src="/test.ico" width={200} height={200} idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="5" src="data:image/png;base64
nt} setIdToCount={setIdToCount} /> <ImageWithMessage id="3" src="/test.svg" width="1200" height="1200" idToCount={idToCount} setIdToCount={setIdToCount} /
{ "filepath": "test/e2e/next-image-new/default/pages/on-loading-complete.js", "language": "javascript", "file_size": 3129, "cut_index": 614, "middle_length": 229 }
import Image from 'next/image' const Page = () => { return ( <div> <p>Preload Page</p> <Image preload id="basic-image" alt="basic-image" src="/test.jpg" width="400" height="400" ></Image> <Image preload id="basic-image-cross...
g="eager" id="load-eager" alt="load-eager" src="/test.png" width="200" height="200" ></Image> <Image preload id="responsive1" alt="responsive1" src="/wide.png" widt
ad id="basic-image-referrerpolicy" alt="basic-image-referrerpolicy" src="/test.png" width="400" height="400" referrerPolicy="no-referrer" ></Image> <Image loadin
{ "filepath": "test/e2e/next-image-new/default/pages/preload.js", "language": "javascript", "file_size": 1697, "cut_index": 537, "middle_length": 229 }
import Image from 'next/image' const Page = () => { return ( <div> <p>Priority Page</p> <Image priority id="basic-image" alt="basic-image" src="/test.jpg" width="400" height="400" ></Image> <Image priority id="basic-image-cr...
ading="eager" id="load-eager" alt="load-eager" src="/test.png" width="200" height="200" ></Image> <Image priority id="responsive1" alt="responsive1" src="/wide.png"
iority id="basic-image-referrerpolicy" alt="basic-image-referrerpolicy" src="/test.png" width="400" height="400" referrerPolicy="no-referrer" ></Image> <Image lo
{ "filepath": "test/e2e/next-image-new/default/pages/priority.js", "language": "javascript", "file_size": 1705, "cut_index": 537, "middle_length": 229 }
mport testPNG from '../public/test.png' import testWEBP from '../public/test.webp' import testAVIF from '../public/test.avif' import testSVG from '../public/test.svg' import testGIF from '../public/test.gif' import testBMP from '../public/test.bmp' import testICO from '../public/test.ico' import widePNG from '../public...
y93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImciPgogICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjMzMzIiBvZmZzZXQ9IjIwJSIgLz4KICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iIzIyMiIgb2Zmc2V0PSI1MCUiI
png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNM/s/wBwAFjwJgf8HDLgAAAABJRU5ErkJggg==' const shimmer = `data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6L
{ "filepath": "test/e2e/next-image-new/default/pages/static-img.js", "language": "javascript", "file_size": 5177, "cut_index": 716, "middle_length": 229 }
ort React from 'react' import Image from 'next/image' const Page = () => { return ( <div> <p>Wrapper Div</p> <div id="image-container1"> <Image id="img1" src="/wide.png" width="1200" height="700" loading="eager" /> </div> <...
h="400" height="400" loading="eager" /> </div> <div id="image-container4"> <Image id="img4" src="/test.png" width="400" height="400" loading="eager"
width: '100%', objectPosition: '30% 30%', }} sizes="50vh" /> </div> <div id="image-container3"> <Image id="img3" src="/test.png" widt
{ "filepath": "test/e2e/next-image-new/default/pages/wrapper-div.js", "language": "javascript", "file_size": 1104, "cut_index": 515, "middle_length": 229 }
nextTestSetup } from 'e2e-utils' describe('Image Component from node_modules', () => { const { next } = nextTestSetup({ files: __dirname, }) it('should apply image config for node_modules', async () => { const browser = await next.browser('/') const src = await browser .elementById('image-fro...
ld warn when using images.domains config', async () => { expect(next.cliOutput).toContain( '`images.domains` is deprecated in favor of `images.remotePatterns`. Please update next.config.js to protect your application from malicious users.' )
expect(srcset).toMatch('1234') }) it('shou
{ "filepath": "test/e2e/next-image-new/image-from-node-modules/image-from-node-modules.test.ts", "language": "typescript", "file_size": 836, "cut_index": 520, "middle_length": 52 }
' import { retry } from 'next-test-utils' describe('TypeScript Image Component Build Errors', () => { if (isNextDev) { it('no-op in dev', () => {}) return } const { next } = nextTestSetup({ files: __dirname, skipStart: true, skipDeployment: true, }) it('should fail to build invalid usag...
{ await next.patchFile( 'next.config.js', (content) => content.replace('// disableStaticImages', 'disableStaticImages'), async () => { const { exitCode } = await next.build() expect(next.cliOutput).toMatch(/Fai
nable to type/) expect(exitCode).toBe(1) const envTypes = await next.readFile('next-env.d.ts') expect(envTypes).toContain('image-types/global') }) it('should remove global image types when disabled', async () =>
{ "filepath": "test/e2e/next-image-new/typescript/typescript.test.ts", "language": "typescript", "file_size": 2561, "cut_index": 563, "middle_length": 229 }
import Image from 'next/image' const Invalid = () => { return ( <div> <h1>Invalid TS</h1> <Image id="invalid-src" alt="invalid-src" src={new Date()} width={500} height={500} /> <Image id="invalid-width" alt="invalid-width" s...
ring-type" src="https://image-optimization-test.vercel.app/test.jpg" width="500foo" /> <Image id="invalid-height-string-type" alt="invalid-height-string-type" src="https://image-optimization-test.vercel.a
" src="https://image-optimization-test.vercel.app/test.jpg" width="500" height="500" placeholder="invalid" /> <Image id="invalid-width-string-type" alt="invalid-width-st
{ "filepath": "test/e2e/next-image-new/typescript/pages/invalid.tsx", "language": "tsx", "file_size": 1669, "cut_index": 537, "middle_length": 229 }
ort svg from '../public/test.svg' import avif from '../public/test.avif' import { ImageCard } from '../components/image-card' import { DynamicSrcImage } from '../components/image-dynamic-src' import { ImageWithLoader } from '../components/image-with-loader' const Page = () => { return ( <div> <p>Valid TS</...
d="fill-no-width-and-height" src="https://image-optimization-test.vercel.app/test.jpg" fill alt="" /> <Image id="quality-num" src="https://image-optimization-test.vercel.app/test.jpg" quality={80}
/> <Image id="width-and-height-str" alt="width-and-height-str" src="https://image-optimization-test.vercel.app/test.jpg" width="500" height="500" /> <Image i
{ "filepath": "test/e2e/next-image-new/typescript/pages/valid.tsx", "language": "tsx", "file_size": 3122, "cut_index": 614, "middle_length": 229 }
itForNoRedbox, waitForRedbox, } from 'next-test-utils' describe('Image localPatterns config', () => { const { next } = nextTestSetup({ files: __dirname, skipDeployment: true, }) async function getSrc(browser: Playwright, id: string) { const src = await browser.elementById(id).getAttribute('src') ...
romise.all(urls.map((url) => next.fetch(url))) const statuses = responses.map((res) => res.status) expect(statuses).toStrictEqual([200, 200]) }) it.each([ 'does-not-exist', 'nested-assets-query', 'nested-blocked', 'top-level',
t.browser('/') if (isNextDev) { await waitForNoRedbox(browser) } const ids = ['nested-assets', 'static-img'] const urls = await Promise.all(ids.map((id) => getSrc(browser, id))) const responses = await P
{ "filepath": "test/e2e/next-image-new/app-dir-localpatterns/app-dir-localpatterns.test.ts", "language": "typescript", "file_size": 3418, "cut_index": 614, "middle_length": 229 }
=> { const { next } = nextTestSetup({ files: __dirname, skipDeployment: true, }) it('should load static unicode image', async () => { const browser = await next.browser('/') const src = await browser.elementById('static').getAttribute('src') expect(src).toMatch( /_next%2Fstatic%2F(immu...
ch( '/_next/image?url=%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%AD.png' ) const fullSrc = new URL(src, next.url) const res = await next.fetch(fullSrc.pathname + fullSrc.search) expect(res.status).toBe(200) }) it('should load ext
pect(res.status).toBe(200) }) it('should load internal unicode image', async () => { const browser = await next.browser('/') const src = await browser.elementById('internal').getAttribute('src') expect(src).toMat
{ "filepath": "test/e2e/next-image-new/unicode/unicode.test.ts", "language": "typescript", "file_size": 4159, "cut_index": 614, "middle_length": 229 }
mport { check, retry } from 'next-test-utils' const pathnames = { '/404': ['/not/a/real/page?with=query', '/not/a/real/page'], // Special handling is done for the error cases because these need to be // prefixed with the basePath if it's enabled for that test suite. These also // should only run when the appli...
s failure in development { basePath: false, i18n: false, middleware: true }, ]), ] const baseNextConfig = ` module.exports = { BASE_PATH I18N } ` describe('404-page-router', () => { const { next } = nextTestSetup({ files: {
rue, i18n: false, middleware: false }, { basePath: true, i18n: true, middleware: false }, { basePath: false, i18n: false, middleware: false }, ...((global as any).isNextDev ? [] : [ // TODO: investigate thi
{ "filepath": "test/e2e/404-page-router/index.test.ts", "language": "typescript", "file_size": 4977, "cut_index": 614, "middle_length": 229 }
r } from 'next/router' import { useEffect, useState } from 'react' import Debug from './debug' function transform(router) { return { pathname: router.pathname, asPath: router.asPath, query: Object.entries(router.query) .map(([key, value]) => [key, value].join('=')) .join('&'), isReady: ro...
<> <dl> <Debug name="pathname" value={debug.pathname} /> <Debug name="asPath" value={debug.asPath} /> <Debug name="query" value={debug.query} /> <Debug name="isReady" value={debug.isReady} /> </dl> {childr
ug(transform(router)) }, [router]) return (
{ "filepath": "test/e2e/404-page-router/app/components/debug-error.js", "language": "javascript", "file_size": 855, "cut_index": 529, "middle_length": 52 }
import { retry } from 'next-test-utils' import { join } from 'path' describe('link-with-api-rewrite', () => { const { next } = nextTestSetup({ files: { pages: new FileRef(join(__dirname, 'app/pages')), 'next.config.js': new FileRef(join(__dirname, 'app/next.config.js')), }, dependencies: {}, ...
sync () => { expect(await browser.eval('window.beforeNav')).not.toEqual('hi') }) // Check to see that we were in fact navigated to the correct page. const pathname = await browser.eval('window.location.pathname') expect(pat
ill be a hard // navigation later (we do this be checking that the window global is // unset). await browser.eval('window.beforeNav = "hi"') await browser.elementById('rewrite').click() await retry(a
{ "filepath": "test/e2e/link-with-api-rewrite/index.test.ts", "language": "typescript", "file_size": 2340, "cut_index": 563, "middle_length": 229 }
ss.env.__NEXT_CACHE_COMPONENTS === 'true' ? describe.skip : describe)( 'Build Error Tests', () => { const { next, isTurbopack } = nextTestSetup({ files: __dirname, skipStart: true, skipDeployment: true, }) if (isNextDev) { it('no-op in dev', () => {}) return } it(...
( "Module not found: Can't resolve '../../public/foo/test-rect-broken.jpg" ) if (isTurbopack) { expect(cliOutput).toContain('app/static-img/page.js') } else { expect(cliOutput).toContain('./
eplace( '../../public/foo/test-rect.jpg', '../../public/foo/test-rect-broken.jpg' ), async () => { const { cliOutput } = await next.build() expect(cliOutput).toContain
{ "filepath": "test/e2e/next-image-new/app-dir/app-dir-static.test.ts", "language": "typescript", "file_size": 16188, "cut_index": 921, "middle_length": 229 }
e client' import { useState } from 'react' import Image from 'next/image' const Page = () => { const [clicked, setClicked] = useState(false) return ( <div> <h1>Test onError</h1> <p> If error occurred while loading image, native onError should be called. </p> <button id="toggle"...
rred for img${id}`) return ( <> <div className="wrap"> <Image id={`img${id}`} onError={(e) => { setMsg(`error occurred while loading ${e.target.id}`) }} {...props} /> </
src={clicked ? '/404.jpg' : '/test.jpg'} width="200" height="200" /> <div id="footer" /> </div> ) } function ImageWithMessage({ id, ...props }) { const [msg, setMsg] = useState(`no error occu
{ "filepath": "test/e2e/next-image-new/app-dir/app/on-error/page.js", "language": "javascript", "file_size": 1088, "cut_index": 515, "middle_length": 229 }
import Image from 'next/image' const Page = () => { return ( <div> <p>Preload Page</p> <Image preload id="basic-image" alt="basic-image" src="/test.jpg" width="400" height="400" ></Image> <Image preload id="basic-image-cross...
g="eager" id="load-eager" alt="load-eager" src="/test.png" width="200" height="200" ></Image> <Image preload id="responsive1" alt="responsive1" src="/wide.png" widt
ad id="basic-image-referrerpolicy" alt="basic-image-referrerpolicy" src="/test.png" width="400" height="400" referrerPolicy="no-referrer" ></Image> <Image loadin
{ "filepath": "test/e2e/next-image-new/app-dir/app/preload/page.js", "language": "javascript", "file_size": 1697, "cut_index": 537, "middle_length": 229 }
ffect, useState } from 'react' export default function Home() { const [displayImage, setDisplayImage] = useState(true) const refWithCleanup = useCallback((el) => { if (!el) { throw new Error( 'callback refs that returned a cleanup should never be called with null' ) } return () =>...
<div style={{ position: 'relative', width: 10, height: 10 }}> <Image ref={refWithCleanup} priority fill src="/test.jpg" alt="alt" sizes="10px"
/h1> <section> {displayImage ? (
{ "filepath": "test/e2e/next-image-new/app-dir/app/ref-cleanup/page.js", "language": "javascript", "file_size": 963, "cut_index": 582, "middle_length": 52 }
port React from 'react' import Image from 'next/image' export default function Page() { return ( <div> <p>Blurry Placeholder</p> <Image priority id="blurry-placeholder-raw" src="/test.ico" width="400" height="400" placeholder="blur" blurDataURL...
src="/test.bmp" width="400" height="400" placeholder="blur" blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mO0/8/wBwAE/wI85bEJ6gAAAABJRU5ErkJggg==" /> </div> )
<Image id="blurry-placeholder-with-lazy"
{ "filepath": "test/e2e/next-image-new/app-dir/app/blurry-placeholder/page.js", "language": "javascript", "file_size": 824, "cut_index": 514, "middle_length": 52 }
= require('path') // A simple webpack loader that logs when an entry is being processed module.exports = function entryLoggerLoader(source) { const callback = this.async() const resourcePath = this.resourcePath const logFile = path.join(__dirname, '.entry-log') console.log('loader', resourcePath) // Extra...
Path.split('/pages/')[1] || resourcePath } // Log the entry processing with timestamp const logEntry = `${Date.now()}:${pageName}\n` fs.appendFile(logFile, logEntry, (err) => { if (err) { console.error('Failed to write entry log:', err)
ePath.includes('/pages/')) { pageName = resource
{ "filepath": "test/e2e/deferred-entries/entry-logger-loader.js", "language": "javascript", "file_size": 896, "cut_index": 547, "middle_length": 52 }
ls' import { retry } from 'next-test-utils' describe('href resolving trailing-slash', () => { const { next } = nextTestSetup({ files: __dirname, }) it('should route to /blog/another/ correctly', async () => { const browser = await next.browser('/') await browser.elementByCss('#to-blog-another').clic...
'blog slug first-post' ) }) it('should route to /catch-all/hello/world/ correctly', async () => { const browser = await next.browser('/') await browser.elementByCss('#to-catch-all-item').click() await browser.waitForElementByCss('#slu
async () => { const browser = await next.browser('/') await browser.elementByCss('#to-blog-post').click() await browser.waitForElementByCss('#slug') expect(await browser.elementByCss('#slug').text()).toBe(
{ "filepath": "test/e2e/trailing-slashes-href-resolving/trailing-slashes-href-resolving.test.ts", "language": "typescript", "file_size": 2599, "cut_index": 563, "middle_length": 229 }
, Request as PlaywrightRequest } from 'playwright' import { retry } from 'next-test-utils' const _describe = // prefetching is disabled in dev. isNextDev ? describe.skip : describe _describe('app dir - form prefetching', () => { const { next } = nextTestSetup({ files: __dirname, nextConfig: { type...
1' const isPrefetch = !!headers[NEXT_ROUTER_PREFETCH_HEADER] return isRSC && !isPrefetch }, log: true, }) const session = await next.browser('/forms/basic', { beforePageLoad: interceptor.beforePageLoad, })
pattern: '**/search*', requestFilter: async (request) => { // only capture RSC requests that *aren't* prefetches const headers = await request.allHeaders() const isRSC = headers[RSC_HEADER] === '
{ "filepath": "test/e2e/next-form/default/next-form-prefetch.test.ts", "language": "typescript", "file_size": 7844, "cut_index": 716, "middle_length": 229 }
'react' import { type ComponentProps, useActionState, useState } from 'react' import Form from 'next/form' import { useRouter } from 'next/navigation' export default function Page() { const destination = '/redirected-from-action' const [query, setQuery] = useState('') return ( <Form action="/search" id="sea...
</NavigateButton> </Form> ) } function NavigateButton({ to, ...props }: { to: string } & ComponentProps<'button'>) { const router = useRouter() const [, dispatch] = useActionState(() => router.push(to), undefined) return <button type="subm
s({ query })}> Submit (client action)
{ "filepath": "test/e2e/next-form/default/app/forms/with-function/button-formaction-client/page.tsx", "language": "tsx", "file_size": 897, "cut_index": 547, "middle_length": 52 }
use client' import * as React from 'react' import Form from 'next/form' import { useRouter } from 'next/router' const isReact18 = typeof React.useActionState !== 'function' export default isReact18 ? DummyPage : Page function DummyPage() { return <>This test cannot run in React 18</> } function Page() { const d...
rm> ) } function NavigateButton({ to, ...props }: { to: string } & React.ComponentProps<'button'>) { const router = useRouter() const [, dispatch] = React.useActionState(() => { router.push(to) }, undefined) return <button type="submit"
ry" value={query} onChange={(e) => setQuery(e.target.value)} /> <NavigateButton to={destination + '?' + new URLSearchParams({ query })}> Submit (client action) </NavigateButton> </Fo
{ "filepath": "test/e2e/next-form/default/pages/pages-dir/forms/with-function/button-formaction-client/index.tsx", "language": "tsx", "file_size": 1036, "cut_index": 513, "middle_length": 229 }
lient' import * as React from 'react' import Form from 'next/form' import { useRouter } from 'next/router' export default function Home() { const searchParams = useRouter().query const attribute = searchParams.attribute as string | undefined return ( <div onSubmit={(e) => { // should fire if th...
-form"> <input name="query" /> <button type="submit" formAction="/pages-dir/search" formEncType={ attribute === 'formEncType' ? 'multipart/form-data' : undefined } formMethod={at
ult submit behavior was not prevented') e.preventDefault() // this submission will do something stupid, we don't want it to actually go through. } }} > <Form action="/pages-dir/search" id="search
{ "filepath": "test/e2e/next-form/default/pages/pages-dir/forms/button-formaction-unsupported/index.tsx", "language": "tsx", "file_size": 1198, "cut_index": 518, "middle_length": 229 }
tTestSetup } from 'e2e-utils' describe('app dir - form - with basepath', () => { const { next } = nextTestSetup({ files: __dirname, }) it('should add basePath to `action`', async () => { const session = await next.browser('/base/forms/basic') const start = Date.now() await session.eval(`window....
_ID`)).toEqual(start) }) it("should not add basePath to a submitter's formAction", async () => { const session = await next.browser('/base/forms/button-formaction') const start = Date.now() await session.eval(`window.__MPA_NAV_ID = ${star
s('[type="submit"]') await submitButton.click() const result = await session.waitForElementByCss('#search-results').text() expect(result).toMatch(/query: "my search"/) expect(await session.eval(`window.__MPA_NAV
{ "filepath": "test/e2e/next-form/basepath/next-form-basepath.test.ts", "language": "typescript", "file_size": 1439, "cut_index": 524, "middle_length": 229 }
* as React from 'react' import * as react from 'library-with-exports/react' import * as serverFavoringBrowser from 'library-with-exports/server-favoring-browser' import * as serverFavoringEdge from 'library-with-exports/server-favoring-edge' export const config = { runtime: 'nodejs', } let server = { react: reac...
react.condition, serverFavoringBrowser: serverFavoringBrowser.condition, serverFavoringEdge: serverFavoringEdge.condition, }) }, []) return ( <output aria-busy={client === null}> {client === null ? ( <pre data-testid=
ument.querySelector('[data-testid="server"]')!.textContent! ) } export default function Page() { const [client, setClient] = React.useState<unknown | null>(null) React.useLayoutEffect(() => { setClient({ react:
{ "filepath": "test/e2e/import-conditions/pages/pages/node-page.tsx", "language": "tsx", "file_size": 1231, "cut_index": 518, "middle_length": 229 }
tTestSetup, isNextStart } from 'e2e-utils' ;(process.env.TURBOPACK_DEV && isNextStart ? describe.skip : describe)( 'API routes', () => { const { next, skipped } = nextTestSetup({ files: __dirname, // Assertions don't apply to deploy mode (output differs vs. local Next.js server). skipDeploymen...
t: 'manual', }) expect(res.status).toBe(308) const text = await res.text() expect(text).toEqual('/api/users') }) it('should return data when catch-all with index and trailing slash', async () => { const data = await n
k && res.json()) expect(data).toEqual({ slug: ['1'] }) }) it('should return redirect when catch-all with index and trailing slash', async () => { const res = await next.fetch('/api/users/', { redirec
{ "filepath": "test/e2e/api-catch-all/api-catch-all.test.ts", "language": "typescript", "file_size": 1376, "cut_index": 524, "middle_length": 229 }
.toEqual({ fetchpriority: '', imagesizes: '', imagesrcset: `/_next/image?url=%2Ftest.webp&w=640&q=75${dpl} 1x, /_next/image?url=%2Ftest.webp&w=828&q=75${dpl} 2x`, crossorigin: 'use-credentials', referrerpolicy: '', }) expect( entries.find( (item) => item.im...
.png&w=3840&q=75${dpl} 3840w` ) ).toEqual({ fetchpriority: '', imagesizes: '100vw', imagesrcset: `/_next/image?url=%2Fwide.png&w=640&q=75${dpl} 640w, /_next/image?url=%2Fwide.png&w=750&q=75${dpl} 750w, /_next/image?url=%2Fwide.p
e?url=%2Fwide.png&w=1080&q=75${dpl} 1080w, /_next/image?url=%2Fwide.png&w=1200&q=75${dpl} 1200w, /_next/image?url=%2Fwide.png&w=1920&q=75${dpl} 1920w, /_next/image?url=%2Fwide.png&w=2048&q=75${dpl} 2048w, /_next/image?url=%2Fwide
{ "filepath": "test/e2e/next-image-new/app-dir/app-dir.test.ts", "language": "typescript", "file_size": 75008, "cut_index": 3790, "middle_length": 229 }
mage' // We don't use a static import intentionally const shimmer = `data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgPGRlZnM+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImciPgogICAgICA8...
m9tPSItMjAwIiB0bz0iMjAwIiBkdXI9IjFzIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgIC8+Cjwvc3ZnPg==` export default function Page() { return ( <> <p>Image with fill with Data URL placeholder</p> <div style={{ position: 'relative', display: 'flex', m
cmFkaWVudD4KICA8L2RlZnM+CiAgPHJlY3Qgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIGZpbGw9IiMzMzMiIC8+CiAgPHJlY3QgaWQ9InIiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIiBmaWxsPSJ1cmwoI2cpIiAvPgogIDxhbmltYXRlIHhsaW5rOmhyZWY9IiNyIiBhdHRyaWJ1dGVOYW1lPSJ4IiBmc
{ "filepath": "test/e2e/next-image-new/app-dir/app/fill-data-url-placeholder/page.js", "language": "javascript", "file_size": 1880, "cut_index": 537, "middle_length": 229 }
t/link' export default function Page() { return ( <div> This is a static page. <br /> <Runtime /> <br /> <Time /> <br /> <Link href="/node-rsc" id="link-node-rsc"> to /node-rsc </Link> <br /> <Link href="/node-rsc-ssg" id="link-node-rsc-ssg"> ...
</Link> <br /> <Link href="/node-ssg" id="link-node-ssg"> to /node-ssg </Link> <br /> <Link href="/node-ssr" id="link-node-ssr"> to /node-ssr </Link> </div> ) } export const config = { runtime
id="link-node-rsc-isr"> to /node-rsc-isr
{ "filepath": "test/e2e/switchable-runtime/pages/node.js", "language": "javascript", "file_size": 928, "cut_index": 606, "middle_length": 52 }
g') const callbackLogFile = path.join(__dirname, '.callback-log') const deferredPageFile = path.join(__dirname, 'app', 'deferred', 'page.tsx') const routeHandlerFile = path.join( __dirname, 'app', 'route-handler', 'route.ts' ) const homePageFile = path.join(__dirname, 'app', 'page.tsx') let lastHomePageContent...
Mutate the deferred entry source directly so the deferred build picks // up callback-time content. if (shouldWriteDeferredTimestamp) { const deferredPageContent = fs.readFileSync(deferredPageFile, 'utf-8') const nextDeferredPage
nst timestamp = Date.now() const homePageContent = fs.readFileSync(homePageFile, 'utf-8') const shouldWriteDeferredTimestamp = lastHomePageContent === null || lastHomePageContent !== homePageContent //
{ "filepath": "test/e2e/deferred-entries/next.config.js", "language": "javascript", "file_size": 3526, "cut_index": 614, "middle_length": 229 }
nction Index() { return ( <> <Link href="/blog/another/" id="to-blog-another"> to /blog/another/ </Link> <br /> <Link href="/blog/first-post/" id="to-blog-post"> to /blog/first-post/ </Link> <br /> <Link href="/catch-all/hello/world/" id="to-catch-all-item...
ther/ </Link> <br /> <Link href="/top-level-slug/" id="to-slug"> to /top-level-slug/ </Link> <br /> <Link as="/world" href="/[slug]" id="to-slug-manual"> to /world/ </Link> <br /> </> )
nk href="/another/" id="to-another"> to /ano
{ "filepath": "test/e2e/trailing-slashes-href-resolving/pages/index.js", "language": "javascript", "file_size": 869, "cut_index": 559, "middle_length": 52 }
import React, { Suspense } from 'react' import Form from 'next/form' type AnySearchParams = Promise<{ [key: string]: string | Array<string> | undefined }> function Home({ searchParams }: { searchParams: AnySearchParams }) { const attribute = React.use(searchParams).attribute return ( <div onSubmit={...
action="/search" id="search-form"> <input name="query" /> <button type="submit" formAction="/search" formEncType={ attribute === 'formEncType' ? 'multipart/form-data' : undefined }
console.log('correct: default submit behavior was not prevented') e.preventDefault() // this submission will do something stupid, we don't want it to actually go through. } }} > <Form
{ "filepath": "test/e2e/next-form/default/app/forms/button-formaction-unsupported/page.tsx", "language": "tsx", "file_size": 1443, "cut_index": 524, "middle_length": 229 }
lient' import * as React from 'react' import * as react from 'library-with-exports/react' import * as serverFavoringBrowser from 'library-with-exports/server-favoring-browser' import * as serverFavoringEdge from 'library-with-exports/server-favoring-edge' export default function ClientPage({ action, server, }: { ...
ion, }) }, []) return ( <form action={formAction}> <input type="submit" /> <output aria-busy={client === null || isPending}> {client === null ? ( <pre>{JSON.stringify({ server }, null, 2)}</pre> ) : (
ent] = React.useState<unknown | null>(null) React.useEffect(() => { setClient({ react: react.condition, serverFavoringBrowser: serverFavoringBrowser.condition, serverFavoringEdge: serverFavoringEdge.condit
{ "filepath": "test/e2e/import-conditions/app/app/ClientPage.tsx", "language": "tsx", "file_size": 1156, "cut_index": 518, "middle_length": 229 }
2ftest-file.txt') }) it('should prevent traversing with /..%2f..%2f..%2f..%2ftest-file.txt', async () => { await expectStatus('/..%2f..%2f..%2f..%2ftest-file.txt') }) it('should prevent traversing with /..%2f..%2f..%2f..%2f..%2ftest-file.txt', async () => { await expectStatus('/..%2f..%2f..%2f..%2f..%...
/..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2ftest-file.txt', async () => { await expectStatus('/..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2ftest-file.txt') }) it('should prevent traversing with /%2e%2e/test-file.txt', async () => { await expectStatus(
}) it('should prevent traversing with /..%2f..%2f..%2f..%2f..%2f..%2f..%2ftest-file.txt', async () => { await expectStatus('/..%2f..%2f..%2f..%2f..%2f..%2f..%2ftest-file.txt') }) it('should prevent traversing with
{ "filepath": "test/e2e/file-serving/file-serving.test.ts", "language": "typescript", "file_size": 242762, "cut_index": 7068, "middle_length": 229 }
ort React from 'react' import Image from 'next/image' const Page = () => { return ( <div> <p>Wrapper Div</p> <div id="image-container1"> <Image id="img1" src="/wide.png" width="1200" height="700" loading="eager" /> </div> <...
h="400" height="400" loading="eager" /> </div> <div id="image-container4"> <Image id="img4" src="/test.png" width="400" height="400" loading="eager"
width: '100%', objectPosition: '30% 30%', }} sizes="50vh" /> </div> <div id="image-container3"> <Image id="img3" src="/test.png" widt
{ "filepath": "test/e2e/next-image-new/app-dir/app/wrapper-div/page.js", "language": "javascript", "file_size": 1104, "cut_index": 515, "middle_length": 229 }
typescript: { ignoreBuildErrors: true, }, }, }) const isAppDir = type === 'app' const pathPrefix = isAppDir ? '' : '/pages-dir' it( 'should soft-navigate on submit' + (isAppDir ? ' and show the prefetched loading state' : ''), async () => { const s...
ading state, so it should be displayed await session.waitForElementByCss('#loading') } const result = await session .waitForElementByCss('#search-results') .text() expect(result).toMatch(/query: "my se
y"]') await searchInput.fill('my search') const submitButton = await session.elementByCss('[type="submit"]') await submitButton.click() if (isAppDir) { // we should have prefetched a lo
{ "filepath": "test/e2e/next-form/default/shared-tests.util.ts", "language": "typescript", "file_size": 10517, "cut_index": 921, "middle_length": 229 }
deployed { 'library-with-exports': 'file:./library-with-exports', } : { 'library-with-exports': 'link:./library-with-exports', } const { next } = nextTestSetup({ files: __dirname, dependencies, }) it('Pages Router page headers with edge runtime', async () => { ...
', serverFavoringBrowser: 'browser', serverFavoringEdge: 'edge-light', }) }) it('Pages Router page with edge runtime', async () => { const browser = await next.browser('/pages/edge-page') const json = await browser.elementByCs
( 'x-server-favoring-browser-condition' ), serverFavoringEdge: response.headers.get( 'x-server-favoring-edge-condition' ), } expect(middlewareHeaders).toEqual({ react: 'react-server
{ "filepath": "test/e2e/import-conditions/import-conditions.test.ts", "language": "typescript", "file_size": 8615, "cut_index": 716, "middle_length": 229 }
/ Hoisted state to count each image load callback const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) return ( <div> <h1>On Loading Complete Test</h1> <ImageWithMessage id="1" src="/test.jpg" width="128" height="128" ...
ToCount} /> <ImageWithMessage id="4" src="/test.ico" width={200} height={200} idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="5" src="data:
ToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="3" src="/test.svg" width="1200" height="1200" idToCount={idToCount} setIdToCount={setId
{ "filepath": "test/e2e/next-image-new/app-dir/app/on-loading-complete/page.js", "language": "javascript", "file_size": 3148, "cut_index": 614, "middle_length": 229 }
rt * as React from 'react' import Form from 'next/form' import { useRouter } from 'next/router' const isReact18 = typeof React.useActionState !== 'function' export default isReact18 ? DummyPage : Page function DummyPage() { return <>This test cannot run in React 18</> } function Page() { const destination = '/p...
React.useState('') return ( <Form action={dispatch} id="search-form"> <input name="query" value={query} onChange={(e) => setQuery(e.target.value)} /> <button type="submit">Submit (client action)</button>
ush(to) }, undefined) const [query, setQuery] =
{ "filepath": "test/e2e/next-form/default/pages/pages-dir/forms/with-function/action-client/index.tsx", "language": "tsx", "file_size": 853, "cut_index": 529, "middle_length": 52 }
nc(logPath, 'utf-8') const lines = content.split('\n').filter(Boolean) if (lines.length === 0) { return null } const [, timestamp] = lines[0].split(':') return parseInt(timestamp, 10) } function parseCurrentTimeTimestamp(html: string): number { const match = html.match(/id="current-time">(\d+)</) if ...
1], 10) } async function expectPngResponse(res: Response) { expect(res.status).toBe(200) expect(res.headers.get('content-type')).toContain('image/png') const body = Buffer.from(await res.arrayBuffer()) expect(body.byteLength).toBeGreaterThan(8)
const match = html.match( /id="deferred-callback-timestamp">(?:<!-- -->)?(\d+)/ ) if (!match) { throw new Error( 'Could not find deferred callback timestamp in response HTML' ) } return parseInt(match[
{ "filepath": "test/e2e/deferred-entries/deferred-entries.test.ts", "language": "typescript", "file_size": 26549, "cut_index": 1331, "middle_length": 229 }
jpg from '../public/test.jpg' import png from '../public/test.png' import avif from '../public/test.avif' import webp from '../public/test.webp' const Page = () => { return ( <> <h1>Layout fill inside non-relative parent</h1> <div style={{ position: 'static', width: '200px', height: '200px' }}> ...
sition: 'absolute', width: '200px', height: '200px' }}> <Image id="absolute" layout="fill" priority src={avif} /> </div> <div style={{ position: 'relative', width: '200px', height: '200px' }}> <Image id="relative" layout="fill"
ity src={png} /> </div> <div style={{ po
{ "filepath": "test/e2e/next-image-legacy/default/pages/layout-fill-inside-nonrelative.js", "language": "javascript", "file_size": 996, "cut_index": 582, "middle_length": 52 }
from 'react' import Image from 'next/legacy/image' const Page = () => { return ( <div> <p>Layout Fill</p> <div style={{ position: 'relative', width: '600px', height: '350px' }}> <Image id="fill1" src="/wide.png" layout="fill" /> </div> <p>Layout Fill</p> <div style={{ posit...
objectFit="cover" objectPosition="left center" sizes="(min-width: 1200px) 90vw, (min-width: 800px) 30vw, 100vw" /> </div> <p>Layout Fill</p> <div style={{ position: 'rel
"left center" /> </div> <p>Layout Fill</p> <div style={{ position: 'relative', width: '50vw', height: '50vh' }}> <Image id="fill3" src="/wide.png" layout="fill"
{ "filepath": "test/e2e/next-image-legacy/default/pages/layout-fill.js", "language": "javascript", "file_size": 1290, "cut_index": 524, "middle_length": 229 }
port React from 'react' import Image from 'next/legacy/image' const Page = () => { return ( <div> <p>Layout Intrinsic</p> <Image id="intrinsic1" src="/wide.png" width="1200" height="700" layout="intrinsic" ></Image> <Image id="intrinsic2" ...
00" layout="intrinsic" ></Image> <Image id="intrinsic4" src="/wide.png" width="1200" height="700" layout="intrinsic" ></Image> <p>Layout Intrinsic</p> </div> ) } export default
height="7
{ "filepath": "test/e2e/next-image-legacy/default/pages/layout-intrinsic.js", "language": "javascript", "file_size": 789, "cut_index": 514, "middle_length": 14 }
, { useRef } from 'react' import Image from 'next/legacy/image' const Page = () => { const myRef = useRef(null) return ( <> <div ref={myRef} style={{ width: '100%', height: '400px', position: 'relative', overflowY: 'scroll', }} > ...
c="/test.png" alt="mine" width="400" height="400" lazyBoundary="1800px" /> <Image lazyRoot={myRef} id="myImage3" src="/test.svg" alt="mine"
src="/test.jpg" alt="mine" width="400" height="400" lazyBoundary="1500px" /> <Image lazyRoot={myRef} id="myImage2" sr
{ "filepath": "test/e2e/next-image-legacy/default/pages/lazy-withref.js", "language": "javascript", "file_size": 1387, "cut_index": 524, "middle_length": 229 }
import { useState } from 'react' import Image from 'next/legacy/image' const Page = () => { return ( <div> <h1>Test onError</h1> <p> If error occurred while loading image, native onError should be called. </p> <ImageWithMessage id="1" src="/test.png" layout="fill" /> <Image...
${id}`} onError={(e) => { const msg = `error occurred while loading ${e.target.id}` setMsg(msg) }} {...props} /> </div> <p id={`msg${id}`}>{msg}</p> <hr /> </> ) } expor
ror occurred') const style = props.layout === 'fill' ? { position: 'relative', width: '64px', height: '64px' } : {} return ( <> <div className="wrap" style={style}> <Image id={`img
{ "filepath": "test/e2e/next-image-legacy/default/pages/on-error.js", "language": "javascript", "file_size": 1012, "cut_index": 512, "middle_length": 229 }
'next/legacy/image' const Page = () => { // Hoisted state to count each image load callback const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) return ( <div> <h1>Test onLoad</h1> <p> This is the native onLoad which doesn't work as many places a...
dToCount={setIdToCount} /> <ImageWithMessage id="3" src="/test.svg" layout="responsive" width="1200" height="1200" idToCount={idToCount} setIdToCount={setIdToCount} /> <Image
oCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="2" src={require('../public/test.png')} placeholder="blur" layout="fixed" idToCount={idToCount} setI
{ "filepath": "test/e2e/next-image-legacy/default/pages/on-load.js", "language": "javascript", "file_size": 2396, "cut_index": 563, "middle_length": 229 }
ted state to count each image load callback const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) return ( <div> <h1>On Loading Complete Test</h1> <ImageWithMessage id="1" src="/test.jpg" layout="intrinsic" width="128" ...
ight="1200" idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="4" src="/test.ico" layout="fill" objectFit="contain" idToCount={idToCount} setIdToCount={set
="blur" layout="fixed" idToCount={idToCount} setIdToCount={setIdToCount} /> <ImageWithMessage id="3" src="/test.svg" layout="responsive" width="1200" he
{ "filepath": "test/e2e/next-image-legacy/default/pages/on-loading-complete.js", "language": "javascript", "file_size": 3156, "cut_index": 614, "middle_length": 229 }
import Image from 'next/legacy/image' const Page = () => { return ( <div> <p>Priority Page</p> <Image priority id="basic-image" src="/test.jpg" width="400" height="400" ></Image> <Image priority id="basic-image-with-crossorigin" ...
src="/test.png" width="400" height="400" ></Image> <Image loading="eager" id="load-eager" src="/test.png" width="400" height="400" ></Image> <Image priority
referrerPolicy="no-referrer" src="/test.png" width="400" height="400" ></Image> <Image priority id="basic-image-with-referrerpolicy" referrerPolicy="no-referrer"
{ "filepath": "test/e2e/next-image-legacy/default/pages/priority.js", "language": "javascript", "file_size": 1585, "cut_index": 537, "middle_length": 229 }
import testImg from '../public/foo/test-rect.jpg' import testImgProp from '../public/exif-rotation.jpg' import Image from 'next/legacy/image' import testJPG from '../public/test.jpg' import testPNG from '../public/test.png' import testWEBP from '../public/test.webp' import testAVIF from '../public/test.avif' import t...
src={testImg} layout="fixed" placeholder="blur" /> <Image id="basic-staticprop" src={testImgProp} layout="fixed" placeholder="blur" /> <TallImage /> <Image id="defined
s/TallImage' export const getStaticProps = () => ({ props: { testImgProp }, }) const Page = ({ testImgProp }) => { return ( <div> <h1 id="page-header">Static Image</h1> <Image id="basic-static"
{ "filepath": "test/e2e/next-image-legacy/default/pages/static-img.js", "language": "javascript", "file_size": 1904, "cut_index": 537, "middle_length": 229 }
age from 'next/legacy/image' import style from '../style.module.css' const Page = () => { return ( <div id="main-container" className={style.mainContainer}> <h1>Image Style Inheritance</h1> <Image id="img-fixed" layout="fixed" src="/test.jpg" width="400" height...
<Image id="img-fill" layout="fill" src="/test.jpg" objectFit="cover" /> </div> <Image id="img-responsive" layout="responsive" src="/test.jpg" width="400" height="400" /> <footer>Footer</foo
lative', width: '200px', height: '200px' }}>
{ "filepath": "test/e2e/next-image-legacy/default/pages/style-inheritance.js", "language": "javascript", "file_size": 898, "cut_index": 547, "middle_length": 52 }
eact from 'react' import Image from 'next/legacy/image' const Page = () => { return ( <div> <h1>Style prop usage and warnings</h1> <Image layout="fixed" id="with-styles" src="/test.png" width={400} height={400} style={{ borderRadius: '10px', padding: 10...
argin: '15px' }} loading="eager" /> <Image layout="responsive" id="without-styles-responsive" src="/test.webp" width={400} height={400} loading="eager" /> </div> ) } export de
style={{ width: '10px', borderRadius: '10px', m
{ "filepath": "test/e2e/next-image-legacy/default/pages/style-prop.js", "language": "javascript", "file_size": 839, "cut_index": 520, "middle_length": 52 }
oin } from 'path' describe('TypeScript Image Component', () => { const { next, skipped } = nextTestSetup({ files: __dirname, skipStart: true, skipDeployment: true, }) if (skipped) return if (isNextStart) { it('should fail to build invalid usage of the Image component', async () => { cons...
d', async () => { const nextConfigPath = join(next.testDir, 'next.config.js') const content = await fs.readFile(nextConfigPath, 'utf8') await fs.writeFile( nextConfigPath, content.replace('// disableStaticImages', 'disable
1) const envTypes = await fs.readFile( join(next.testDir, 'next-env.d.ts'), 'utf8' ) expect(envTypes).toContain('image-types/global') }) it('should remove global image types when disable
{ "filepath": "test/e2e/next-image-legacy/typescript/typescript.test.ts", "language": "typescript", "file_size": 3157, "cut_index": 614, "middle_length": 229 }
from 'react' import Image from 'next/legacy/image' const Invalid = () => { return ( <div> <h1>Invalid TS</h1> <Image id="invalid-src" src={new Date()} width={500} height={500}></Image> <Image id="invalid-width" src="https://image-optimization-test.vercel.app/test.jpg" w...
alid" ></Image> <Image id="invalid-width-string-type" alt="invalid-width-string-type" src="https://image-optimization-test.vercel.app/test.jpg" width="500foo" /> <Image id="invalid-height-stri
ight="500" layout="invalid" ></Image> <Image id="invalid-placeholder" src="https://image-optimization-test.vercel.app/test.jpg" width="500" height="500" placeholder="inv
{ "filepath": "test/e2e/next-image-legacy/typescript/pages/invalid.tsx", "language": "tsx", "file_size": 1448, "cut_index": 524, "middle_length": 229 }
ng' import svg from '../public/test.svg' import avif from '../public/test.avif' import { ImageCard } from '../components/image-card' import { DynamicSrcImage } from '../components/image-dynamic-src' const Page = () => { return ( <div> <p>Valid TS</p> <Image id="width-and-height-num" s...
on-test.vercel.app/test.jpg" layout="fill" /> </div> <Image id="quality-num" src="https://image-optimization-test.vercel.app/test.jpg" quality={80} width={500} height={500} />
n-test.vercel.app/test.jpg" width="500" height="500" /> <div style={{ position: 'relative', width: 100, height: 100 }}> <Image id="layout-fill" src="https://image-optimizati
{ "filepath": "test/e2e/next-image-legacy/typescript/pages/valid.tsx", "language": "tsx", "file_size": 3219, "cut_index": 614, "middle_length": 229 }
('Image Component Unicode Image URL', () => { const { next } = nextTestSetup({ files: __dirname, }) it('should load static unicode image', async () => { const browser = await next.browser('/') const src = await browser.elementById('static').getAttribute('src') expect(src).toMatch( /_next%2F...
/image?url=%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%AD.png' ) const fullSrc = new URL(src, next.url) const res = await fetch(fullSrc) expect(res.status).toBe(200) }) it('should load external unicode image', async () => { const br
toBe(200) }) it('should load internal unicode image', async () => { const browser = await next.browser('/') const src = await browser.elementById('internal').getAttribute('src') expect(src).toMatch( '/_next
{ "filepath": "test/e2e/next-image-legacy/unicode/unicode.test.ts", "language": "typescript", "file_size": 2229, "cut_index": 563, "middle_length": 229 }
ed Image Tests', () => { const { next } = nextTestSetup({ files: __dirname, }) it('should not optimize any image', async () => { const browser = await next.browser('/') expect( await browser.elementById('internal-image').getAttribute('src') ).toMatch('data:') expect( await browse...
.elementById('static-image').getAttribute('srcset') ).toBeNull() expect( await browser.elementById('external-image').getAttribute('srcset') ).toBeNull() expect( await browser.elementById('eager-image').getAttribute('srcset')
await browser.elementById('eager-image').getAttribute('src') ).toMatch(/\/test\.webp/) expect( await browser.elementById('internal-image').getAttribute('srcset') ).toBeNull() expect( await browser
{ "filepath": "test/e2e/next-image-legacy/unoptimized/unoptimized.test.ts", "language": "typescript", "file_size": 3271, "cut_index": 614, "middle_length": 229 }
t React from 'react' import Image from 'next/legacy/image' import testJpg from '../public/test.jpg' const Page = () => { return ( <div> <h1>Unoptimized Config</h1> <p>Scroll down...</p> <div style={{ height: '1000vh' }} /> <Image id="internal-image" src="/test.png" width={400} height={400...
jpg" width={400} height={400} /> <div style={{ height: '1000vh' }} /> <Image id="eager-image" src="/test.webp" width={400} height={400} loading="eager" /> </div> ) } exp
rcel.app/test.
{ "filepath": "test/e2e/next-image-legacy/unoptimized/pages/index.js", "language": "javascript", "file_size": 804, "cut_index": 517, "middle_length": 14 }
ort { nextTestSetup, isNextDev } from 'e2e-utils' describe('Legacy Image Component assetPrefix Tests', () => { const { next, isTurbopack } = nextTestSetup({ files: __dirname, }) it('should include assetPrefix when placeholder=blur during dev', async () => { if (!isNextDev) return const browser = awa...
se base64 data url with placeholder=blur during production', async () => { if (isNextDev) return const browser = await next.browser('/') const id = 'test1' const bgImage = await browser.eval( `document.getElementById('${id}').style['b
(bgImage).toContain('data:image/jpeg;') } else { expect(bgImage).toMatch( /\/_next\/image\?url=https%3A%2F%2Fexample.com%2Fpre%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=8&q=70/ ) } }) it('should u
{ "filepath": "test/e2e/next-image-legacy/asset-prefix/asset-prefix.test.ts", "language": "typescript", "file_size": 1087, "cut_index": 515, "middle_length": 229 }
rt { nextTestSetup } from 'e2e-utils' import { retry } from 'next-test-utils' describe('Image Component Trailing Slash Tests', () => { const { next } = nextTestSetup({ files: __dirname, }) it('should include trailing slash when trailingSlash is set on config file', async () => { const browser = await ne...
c () => { const srcImage = await browser.eval( `document.getElementById('${id}').src` ) expect(srcImage).toMatch( /\/_next\/image\/\?url=%2F_next%2Fstatic%2F(immutable%2F)?media%2Ftest(.+).jpg&w=828&q=75/ ) })
RL with the optimized image URL await retry(asyn
{ "filepath": "test/e2e/next-image-legacy/trailing-slash/trailing-slash.test.ts", "language": "typescript", "file_size": 830, "cut_index": 516, "middle_length": 52 }
skipDeployment: true, }) if (isNextDev) { it('no-op in dev', () => {}) return } it('should throw build error when import statement is used with missing file', async () => { await next.patchFile( 'pages/static-img.js', (content) => content.replace( '../public/foo/test-...
xt, isTurbopack, skipped } = nextTestSetup({ files: __dirname, skipDeployment: true, }) if (skipped) return let browser: Playwright let html: string beforeAll(async () => { html = await next.render('/docs/static-img') browser =
not found: Can't resolve '../public/foo/test-rect-broken.jpg" ) expect(cliOutput).toContain('pages/static-img.js') } ) }) }) describe('Static Image Component Tests for basePath', () => { const { ne
{ "filepath": "test/e2e/next-image-legacy/base-path/base-path-static.test.ts", "language": "typescript", "file_size": 6071, "cut_index": 716, "middle_length": 229 }
Id(next.testDir, ...)`, which reads the local // `.next/required-server-files.json`. In deploy mode that file lives on // Vercel's infrastructure (not on disk locally), so the constructed // expected URL omits the `&dpl=...` query that Vercel injects at // runtime. The assertions are about local-build U...
rl).toString() ) ) } async function getComputed(browser, id, prop) { const val = await browser.eval(`document.getElementById('${id}').${prop}`) if (typeof val === 'number') { return val } if (typeof val === 'string') {
extDev).getDeploymentIdQuery(true) }) async function getImageUrls(browser) { return await Promise.all( (await browser.elementsByCss('img')).map(async (link) => new URL(await link.getAttribute('src'), next.u
{ "filepath": "test/e2e/next-image-legacy/base-path/base-path.test.ts", "language": "typescript", "file_size": 16060, "cut_index": 921, "middle_length": 229 }
' import Image from 'next/legacy/image' const Page = () => { return ( <div> <p>Layout Intrinsic</p> <Image id="intrinsic1" src="/docs/wide.png" width="1200" height="700" layout="intrinsic" ></Image> <Image id="intrinsic2" src="/docs/...
layout="intrinsic" ></Image> <Image id="intrinsic4" src="/docs/wide.png" width="1200" height="700" layout="intrinsic" ></Image> <p>Layout Intrinsic</p> </div> ) } export default Pa
ight="700"
{ "filepath": "test/e2e/next-image-legacy/base-path/pages/layout-intrinsic.js", "language": "javascript", "file_size": 809, "cut_index": 536, "middle_length": 14 }
port React from 'react' import Image from 'next/legacy/image' const Page = () => { return ( <div> <p>Layout Responsive</p> <Image id="responsive1" src="/docs/wide.png" width="1200" height="700" layout="responsive" /> <Image id="responsive2" ...
ight="700" layout="responsive" /> <Image id="responsive4" src="/docs/wide.png" width="1200" height="700" layout="responsive" /> <p>Layout Responsive</p> </div> ) } export defaul
00" he
{ "filepath": "test/e2e/next-image-legacy/base-path/pages/layout-responsive.js", "language": "javascript", "file_size": 791, "cut_index": 514, "middle_length": 14 }
import testImg from '../public/foo/test-rect.jpg' import Image from 'next/legacy/image' import testJPG from '../public/test.jpg' import testPNG from '../public/test.png' import testWEBP from '../public/test.webp' import testAVIF from '../public/test.avif' import testSVG from '../public/test.svg' import testGIF from '...
ic" src={testPNG} layout="fixed" height="200" width="200" /> <Image id="require-static" src={require('../public/foo/test-rect.jpg')} /> <Image id="basic-non-static" src="/test-rect.jpg"
> <h1 id="page-header">Static Image</h1> <Image id="basic-static" src={testImg} layout="fixed" placeholder="blur" /> <TallImage /> <Image id="defined-size-stat
{ "filepath": "test/e2e/next-image-legacy/base-path/pages/static-img.js", "language": "javascript", "file_size": 1638, "cut_index": 537, "middle_length": 229 }
n } from 'path' import { renderViaHTTP, check } from 'next-test-utils' import { FileRef, nextTestSetup } from 'e2e-utils' describe('React Context', () => { const { next } = nextTestSetup({ files: { pages: new FileRef(join(__dirname, 'app/pages')), 'context.js': new FileRef(join(__dirname, 'app/contex...
der with context after change', async () => { const aboutAppPagePath = 'pages/_app.js' const originalContent = await next.readFile(aboutAppPagePath) await next.patchFile( aboutAppPagePath, originalContent.replace('hello wo
should render correctly with context consumer', async () => { const html = await renderViaHTTP(next.url, '/consumer') expect(html).toMatch(/Value: .*?12345/) }) if ((globalThis as any).isNextDev) { it('should ren
{ "filepath": "test/e2e/ssr-react-context/index.test.ts", "language": "typescript", "file_size": 1311, "cut_index": 524, "middle_length": 229 }
.toBe( 'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037.html' ) }) it('should work using browser', async () => { const browser = await next.browser( '/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037.html' ) expect(await browser.el...
_ua_playoff_polo_2.0, 1327037.html' ) }) }) describe('without .html extension', () => { it('should work when requesting the page directly', async () => { const $ = await next.render$( '/product/shirts_and_tops
const browser = await next.browser('/html-links') await browser.elementByCss('#with-html').click() expect(await browser.waitForElementByCss('#text').text()).toBe( 'Param found: shirts_and_tops, mens
{ "filepath": "test/e2e/middleware-trailing-slash/test/index.test.ts", "language": "typescript", "file_size": 17448, "cut_index": 1331, "middle_length": 229 }
er' export async function middleware(request) { const url = request.nextUrl // this is needed for tests to get the BUILD_ID if (url.pathname.startsWith('/_next/static/__BUILD_ID')) { return NextResponse.next() } if (request.headers.get('x-prerender-revalidate')) { return NextResponse.next({ h...
ame = '/ssg/hello' url.searchParams.set('from', 'middleware') return NextResponse.rewrite(url) } if (url.pathname === '/sha/') { url.pathname = '/shallow' return NextResponse.rewrite(url) } if (url.pathname === '/rewrite-to-dynami
url.pathname = '/ssr-page-2' return NextResponse.rewrite(url) } if (url.pathname === '/') { url.pathname = '/ssg/first' return NextResponse.rewrite(url) } if (url.pathname === '/to-ssg/') { url.pathn
{ "filepath": "test/e2e/middleware-trailing-slash/app/middleware.js", "language": "javascript", "file_size": 2676, "cut_index": 563, "middle_length": 229 }
export default function Shallow({ message }) { const { pathname, query } = useRouter() return ( <div> <ul> <li id="message-contents">{message}</li> <li> <Link href="/sha?hello=world" shallow id="shallow-link"> Shallow link to ?hello=world </Link> </l...
</h1> </li> <li> <h2 id="query" data-query-hello={query.hello}> Current query: <code>{JSON.stringify(query)}</code> </h2> </li> </ul> </div> ) } let i = 0 export const getServerSideP
Current path: <code>{pathname}</code>
{ "filepath": "test/e2e/middleware-trailing-slash/app/pages/shallow.js", "language": "javascript", "file_size": 991, "cut_index": 582, "middle_length": 52 }
{ useEffect } from 'react' import { useState } from 'react' export default function Page(props) { const router = useRouter() const [asPath, setAsPath] = useState( router.isReady ? router.asPath : router.href ) useEffect(() => { if (router.isReady) { setAsPath(router.asPath) } }, [router.as...
ify(props)}</p> </> ) } export function getStaticProps({ params }) { return { props: { now: Date.now(), params, }, } } export function getStaticPaths() { return { paths: ['/ssg/first', '/ssg/hello'], fallback: 'blo
-path">{asPath}</p> <p id="props">{JSON.string
{ "filepath": "test/e2e/middleware-trailing-slash/app/pages/ssg/[slug].js", "language": "javascript", "file_size": 881, "cut_index": 559, "middle_length": 52 }
('Unoptimized Image Tests', () => { const { next } = nextTestSetup({ files: __dirname, skipDeployment: true, }) function runTests(url: string) { it(`should not optimize any image (${url})`, async () => { const browser = await next.browser(url) expect( await browser.elementById('in...
'src') ).toMatch(/\/test.webp(\?dpl=.*)?/) expect( await browser.elementById('internal-image').getAttribute('srcset') ).toBeNull() expect( await browser.elementById('static-image').getAttribute('srcset') ).toB
expect( await browser.elementById('external-image').getAttribute('src') ).toBe('https://image-optimization-test.vercel.app/test.jpg') expect( await browser.elementById('eager-image').getAttribute(
{ "filepath": "test/e2e/next-image-new/unoptimized/unoptimized.test.ts", "language": "typescript", "file_size": 4573, "cut_index": 614, "middle_length": 229 }
t React from 'react' import Image from 'next/image' import testJpg from '../public/test.jpg' const Page = () => { return ( <div> <h1>Unoptimized Config</h1> <p>Scroll down...</p> <div style={{ height: '1000vh' }} /> <Image id="internal-image" src="/test.png" width={400} height={400} /> ...
width={400} height={400} /> <div style={{ height: '1000vh' }} /> <Image id="eager-image" src="/test.webp" width={400} height={400} loading="eager" /> </div> ) } export def
p/test.jpg"
{ "filepath": "test/e2e/next-image-new/unoptimized/pages/index.js", "language": "javascript", "file_size": 797, "cut_index": 517, "middle_length": 14 }
'next-test-utils' describe('Image qualities config', () => { const { next } = nextTestSetup({ files: __dirname, skipDeployment: true, }) async function getSrc(browser: Playwright, id: string) { const src = await browser.elementById(id).getAttribute('src') if (src) { const url = new URL(src...
'should load img when quality 42', async () => { const browser = await next.browser('/') if (isNextDev) { await waitForNoRedbox(browser) } const url = await getSrc(browser, 'q-42') const res = await next.fetch(url) expect(res.
Dev) { await waitForNoRedbox(browser) } const url = await getSrc(browser, 'q-undefined') const res = await next.fetch(url) expect(res.status).toStrictEqual(200) expect(url).toContain('&q=69') }) it(
{ "filepath": "test/e2e/next-image-new/app-dir-qualities/app-dir-qualities.test.ts", "language": "typescript", "file_size": 3510, "cut_index": 614, "middle_length": 229 }
('Image Loader Config with Default Loader and File', () => { const { next } = nextTestSetup({ files: __dirname, }) describe('component', () => { it('should work with loaderFile config, leaving default image optimization enabled', async () => { const browser = await next.browser('/') expect(aw...
g1').naturalWidth !== 0` ) ).toBe(true) }) it('should work with loader prop', async () => { const browser = await next.browser('/') expect(await browser.elementById('img2').getAttribute('src')).toBe( '/logo.png?wi
'/_next/image/?url=/logo.png&w=640&q=50 1x, /_next/image/?url=/logo.png&w=828&q=50 2x' ) expect( await browser.eval( `document.getElementById('img1').complete && document.getElementById('im
{ "filepath": "test/e2e/next-image-new/loader-config-default-loader-with-file/loader-config-default-loader-with-file.test.ts", "language": "typescript", "file_size": 2333, "cut_index": 563, "middle_length": 229 }
port statement is used with missing file', async () => { await next.patchFile( 'pages/static-img.js', (content) => content.replace( '../public/foo/test-rect.jpg', '../public/foo/test-rect-broken.jpg' ), async () => { const { cliOutput } = await next.buil...
tatic Image Component Tests for basePath', () => { const { next, isTurbopack, skipped } = nextTestSetup({ files: __dirname, skipDeployment: true, }) if (skipped) return let browser: Playwright let $: ReturnType<typeof cheerio.load> be
ain('/pages/static-img.js') } else { expect(cliOutput).toContain('./pages/static-img.js') } expect(cliOutput).not.toContain('Import trace for requested module') } ) }) }) describe('S
{ "filepath": "test/e2e/next-image-new/base-path/base-path-static.test.ts", "language": "typescript", "file_size": 10472, "cut_index": 921, "middle_length": 229 }