Unverified Commit 5c350668 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

make static image import output path consistent with other media (#30168)

This will ensure an image hashed consistently regardless of how its imported:

- `import file from "./file.png"` -> /_next/static/media/file.12345678.png
- `url(./file.png)` -> /_next/static/media/file.12345678.png
-  `new URL("./file.png", import.meta.url)` -> /_next/static/media/file.12345678.png
parent 2e51e1bb
......@@ -14,7 +14,7 @@ function nextImageLoader(content) {
const opts = { context, content }
const interpolatedName = loaderUtils.interpolateName(
this,
'/static/image/[path][name].[hash].[ext]',
'/static/media/[name].[hash:8].[ext]',
opts
)
const outputPath = assetPrefix + '/_next' + interpolatedName
......
......@@ -137,7 +137,7 @@ export async function imageOptimizer(
// Should match output from next-image-loader
const isStatic = url.startsWith(
`${nextConfig.basePath || ''}/_next/static/image`
`${nextConfig.basePath || ''}/_next/static/media`
)
const width = parseInt(w, 10)
......
......@@ -32,7 +32,7 @@ describe('Image Component assetPrefix Tests', () => {
`document.getElementById('${id}').style['background-image']`
)
expect(bgImage).toMatch(
/\/_next\/image\?url=https%3A%2F%2Fexample.com%2Fpre%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest(.+).jpg&w=8&q=70/
/\/_next\/image\?url=https%3A%2F%2Fexample.com%2Fpre%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=8&q=70/
)
} finally {
if (browser) {
......
......@@ -72,7 +72,7 @@ const runTests = (isDev = false) => {
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%;filter:blur(20px);background-size:cover;background-image:url(${
isDev
? '"/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest.480a01e5ea850d0231aec0fa94bd23a0.jpg&w=8&q=70"'
? '"/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Ftest.480a01e5.jpg&w=8&q=70"'
: '"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z"'
});background-position:0% 0%"`
)
......@@ -81,7 +81,7 @@ const runTests = (isDev = false) => {
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%;filter:blur(20px);background-size:cover;background-image:url(${
isDev
? '"/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest.eba16dd4cf631c11162a5e9faeb5415b.png&w=8&q=70"'
? '"/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Ftest.eba16dd4.png&w=8&q=70"'
: '"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAAAAAAZhBqgAAAAJklEQVR42mNgkmBkYGXgZGBoY2Co/lPAcOf/dYaCzHwGEBAVEwUAZZIG0TbWicQAAAAASUVORK5CYII="'
});background-position:0% 0%"`
)
......
......@@ -662,7 +662,7 @@ function runTests(mode) {
//server-only tests
it('should not create an image folder in server/chunks', async () => {
expect(
existsSync(join(appDir, '.next/server/chunks/static/image'))
existsSync(join(appDir, '.next/server/chunks/static/media'))
).toBeFalsy()
})
}
......
......@@ -34,7 +34,7 @@ describe('Image Component Trailing Slash Tests', () => {
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest(.+).jpg&w=828&q=75/
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
......@@ -62,7 +62,7 @@ describe('Image Component Trailing Slash Tests', () => {
`document.getElementById('${id}').src`
)
expect(srcImage).toMatch(
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest(.+).jpg&w=828&q=75/
/\/_next\/image\/\?url=%2F_next%2Fstatic%2Fmedia%2Ftest(.+).jpg&w=828&q=75/
)
} finally {
if (browser) {
......
......@@ -20,9 +20,7 @@ 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/
)
expect(src).toMatch(/_next%2Fstatic%2Fmedia%2F%C3%A4%C3%B6%C3%BC(.+)png/)
const fullSrc = new URL(src, `http://localhost:${appPort}`)
const res = await fetch(fullSrc)
expect(res.status).toBe(200)
......
......@@ -682,7 +682,7 @@ function runTests({ w, isDev, domains = [], ttl, isSharp, isOutdatedSharp }) {
if (!isDev) {
const filename = 'test'
const query = {
url: `/_next/static/image/public/${filename}.480a01e5ea850d0231aec0fa94bd23a0.jpg`,
url: `/_next/static/media/${filename}.480a01e5.jpg`,
w,
q: 100,
}
......
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