Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize root path according to trailingSlash option in default next/image loader #21337 #22453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/next/client/image.tsx
Expand Up @@ -9,6 +9,7 @@ import {
import { useIntersection } from './use-intersection'
import { ImageConfigContext } from '../shared/lib/image-config-context'
import { warnOnce } from '../shared/lib/utils'
import { normalizePathTrailingSlash } from './normalize-trailing-slash'

const configEnv = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete
const loadedImageURLs = new Set<string>()
Expand Down Expand Up @@ -877,7 +878,7 @@ function defaultLoader({
return src
}

return `${config.path}?url=${encodeURIComponent(src)}&w=${width}&q=${
quality || 75
}`
return `${normalizePathTrailingSlash(config.path)}?url=${encodeURIComponent(
src
)}&w=${width}&q=${quality || 75}`
}
fliptheweb marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions test/integration/image-optimizer/test/index.test.js
Expand Up @@ -327,6 +327,32 @@ describe('Image Optimizer', () => {
runTests(ctx)
})

describe('Server support for trailingSlash in next.config.js', () => {
let app
let appPort
beforeAll(async () => {
nextConfig.replace(
'{ /* replaceme */ }',
JSON.stringify({
trailingSlash: true,
})
)
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})

it('should return successful response for original loader', async () => {
let res
const query = { url: '/test.png', w: 8, q: 70 }
res = await fetchViaHTTP(appPort, '/_next/image/', query)
expect(res.status).toBe(200)
})
})

describe('Server support for headers in next.config.js', () => {
const size = 96 // defaults defined in server/config.ts
let app
Expand Down