From 4546f6dba36bb0cfd72ebb1051a9d320937e8ef1 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 27 Oct 2020 06:13:23 -0400 Subject: [PATCH 1/2] Adjust default image quality to 75 --- docs/api-reference/next/image.md | 2 +- packages/next/client/image.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api-reference/next/image.md b/docs/api-reference/next/image.md index 10662adc85259..423d10c424827 100644 --- a/docs/api-reference/next/image.md +++ b/docs/api-reference/next/image.md @@ -49,7 +49,7 @@ export default Home - `width` - The intrinsic width of the source image in pixels. Must be an integer without a unit. Required unless `unsized` is true. - `height` - The intrinsic height of the source image, in pixels. Must be an integer without a unit. Required unless `unsized` is true. - `sizes` - Defines what proportion of the screen you expect the image to take up. Recommended, as it helps serve the correct sized image to each device. [More info](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes). -- `quality` - The quality of the optimized image, an integer between 1 and 100 where 100 is the best quality. Default 100. +- `quality` - The quality of the optimized image, an integer between 1 and 100 where 100 is the best quality. Default 75. - `loading` - The loading behavior. When `lazy`, defer loading the image until it reaches a calculated distance from the viewport. When `eager`, load the image immediately. Default `lazy`. [More info](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading) - `priority` - When true, the image will be considered high priority and [preload](https://web.dev/preload-responsive-images/). - `unoptimized` - When true, the source image will be served as-is instead of resizing and changing quality. diff --git a/packages/next/client/image.tsx b/packages/next/client/image.tsx index d938348a338aa..a3a2e5e4d1c61 100644 --- a/packages/next/client/image.tsx +++ b/packages/next/client/image.tsx @@ -443,6 +443,6 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string { } return `${root}?url=${encodeURIComponent(src)}&w=${width}&q=${ - quality || '100' + quality || '75' }` } From 196e347a30000bec843ce2be3e078dc1bb5ac766 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Tue, 27 Oct 2020 06:50:45 -0400 Subject: [PATCH 2/2] add tests --- .../default/test/index.test.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/integration/image-component/default/test/index.test.js b/test/integration/image-component/default/test/index.test.js index c2c62f1412780..c2c6eda216076 100644 --- a/test/integration/image-component/default/test/index.test.js +++ b/test/integration/image-component/default/test/index.test.js @@ -22,6 +22,19 @@ const nextConfig = join(appDir, 'next.config.js') let appPort let app +async function hasImageMatchingUrl(browser, url) { + const links = await browser.elementsByCss('img') + let foundMatch = false + for (const link of links) { + const src = await link.getAttribute('src') + if (src === url) { + foundMatch = true + break + } + } + return foundMatch +} + function runTests(mode) { it('should load the images', async () => { let browser @@ -54,6 +67,16 @@ function runTests(mode) { return 'result-correct' }, /result-correct/) + + expect( + await hasImageMatchingUrl( + browser, + mode === 'serverless' + ? // FIXME: this is a bug + `http://localhost:${appPort}/_next/image/?url=%2Ftest.jpg&w=420&q=75` + : `http://localhost:${appPort}/_next/image?url=%2Ftest.jpg&w=420&q=75` + ) + ).toBe(true) } finally { if (browser) { await browser.close()