Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix image optimization encoding url (#28045)
- Fixes #27973 - Reverts #27671 The problem with PR #27671 is that it was encoding too often when it really only needed to solve the bug for `next build && next start` since `next dev` was already working. This PR uses the alternative solution mentioned here #27210 (comment)
- Loading branch information
Showing
7 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
images: { | ||
domains: ['image-optimization-test.vercel.app'], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react' | ||
import Image from 'next/image' | ||
import img from '../public/äöü.png' | ||
|
||
const Page = () => { | ||
return ( | ||
<div> | ||
<h1>Unicode Image URL</h1> | ||
<Image id="static" src={img} /> | ||
<Image id="internal" src="/äöü.png" width={400} height={400} /> | ||
<Image | ||
id="external" | ||
src="https://image-optimization-test.vercel.app/äöü.png" | ||
width={400} | ||
height={400} | ||
/> | ||
<Image | ||
id="internal-space" | ||
src="/hello%20world.jpg" | ||
width={200} | ||
height={200} | ||
/> | ||
<Image | ||
id="external-space" | ||
src="https://image-optimization-test.vercel.app/hello%20world.jpg" | ||
width={200} | ||
height={200} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions
96
test/integration/image-component/unicode/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint-env jest */ | ||
|
||
import { | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
//import fetch from 'node-fetch' | ||
import { join } from 'path' | ||
|
||
jest.setTimeout(1000 * 60) | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
let appPort | ||
let app | ||
let browser | ||
|
||
function runTests() { | ||
it('should load static unicode image', async () => { | ||
const src = await browser.elementById('static').getAttribute('src') | ||
expect(src).toMatch( | ||
/_next%2Fstatic%2Fimage%2Fpublic%2F%C3%A4%C3%B6%C3%BC(.+)png/ | ||
) | ||
const res = await fetch(src) | ||
expect(res.status).toBe(200) | ||
}) | ||
|
||
it('should load internal unicode image', async () => { | ||
const src = await browser.elementById('internal').getAttribute('src') | ||
expect(src).toMatch('/_next/image?url=%2F%C3%A4%C3%B6%C3%BC.png') | ||
const res = await fetch(src) | ||
expect(res.status).toBe(200) | ||
}) | ||
|
||
it('should load external unicode image', async () => { | ||
const src = await browser.elementById('external').getAttribute('src') | ||
expect(src).toMatch( | ||
'/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2F%C3%A4%C3%B6%C3%BC.png' | ||
) | ||
const res = await fetch(src) | ||
expect(res.status).toBe(200) | ||
}) | ||
|
||
it('should load internal image with space', async () => { | ||
const src = await browser.elementById('internal-space').getAttribute('src') | ||
expect(src).toMatch('/_next/image?url=%2Fhello%2520world.jpg') | ||
const res = await fetch(src) | ||
expect(res.status).toBe(200) | ||
}) | ||
|
||
it('should load external image with space', async () => { | ||
const src = await browser.elementById('external-space').getAttribute('src') | ||
expect(src).toMatch( | ||
'/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2Fhello%2520world.jpg' | ||
) | ||
const res = await fetch(src) | ||
expect(res.status).toBe(200) | ||
}) | ||
} | ||
|
||
describe('Image Component Unicode Image URL', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
browser = await webdriver(appPort, '/') | ||
}) | ||
afterAll(() => { | ||
killApp(app) | ||
if (browser) { | ||
browser.close() | ||
} | ||
}) | ||
runTests() | ||
}) | ||
|
||
describe('server mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
browser = await webdriver(appPort, '/') | ||
}) | ||
afterAll(() => { | ||
killApp(app) | ||
if (browser) { | ||
browser.close() | ||
} | ||
}) | ||
runTests() | ||
}) | ||
}) |