Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
0a1d418a
Unverified
Commit
0a1d418a
authored
Jun 08, 2021
by
Yamagishi Kazutoshi
Committed by
GitHub
Jun 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not remove placeholder for data URL (#24704)
parent
3b76d337
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
8 deletions
+55
-8
image.tsx
packages/next/client/image.tsx
+4
-2
blurry-placeholder.js
...ation/image-component/default/pages/blurry-placeholder.js
+11
-0
index.test.js
test/integration/image-component/default/test/index.test.js
+40
-6
No files found.
packages/next/client/image.tsx
View file @
0a1d418a
...
@@ -269,14 +269,16 @@ function removePlaceholder(
...
@@ -269,14 +269,16 @@ function removePlaceholder(
placeholder
:
PlaceholderValue
placeholder
:
PlaceholderValue
)
{
)
{
if
(
placeholder
===
'blur'
&&
element
)
{
if
(
placeholder
===
'blur'
&&
element
)
{
if
(
element
.
complete
)
{
if
(
element
.
complete
&&
!
element
.
src
.
startsWith
(
'data:'
)
)
{
// If the real image fails to load, this will still remove the placeholder.
// If the real image fails to load, this will still remove the placeholder.
// This is the desired behavior for now, and will be revisited when error
// This is the desired behavior for now, and will be revisited when error
// handling is worked on for the image component itself.
// handling is worked on for the image component itself.
element
.
style
.
backgroundImage
=
'none'
element
.
style
.
backgroundImage
=
'none'
}
else
{
}
else
{
element
.
onload
=
()
=>
{
element
.
onload
=
()
=>
{
element
.
style
.
backgroundImage
=
'none'
if
(
!
element
.
src
.
startsWith
(
'data:'
))
{
element
.
style
.
backgroundImage
=
'none'
}
}
}
}
}
}
}
...
...
test/integration/image-component/default/pages/blurry-placeholder.js
View file @
0a1d418a
...
@@ -14,6 +14,17 @@ export default function Page() {
...
@@ -14,6 +14,17 @@ export default function Page() {
placeholder
=
"blur"
placeholder
=
"blur"
blurDataURL
=
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E"
blurDataURL
=
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E"
/>
/>
<
div
id
=
"spacer"
style
=
{{
height
:
'100vh'
}}
/
>
<
Image
id
=
"blurry-placeholder-with-lazy"
src
=
"/test.jpg"
width
=
"400"
height
=
"400"
placeholder
=
"blur"
blurDataURL
=
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E"
/>
<
/div
>
<
/div
>
)
)
}
}
test/integration/image-component/default/test/index.test.js
View file @
0a1d418a
...
@@ -51,6 +51,12 @@ async function getComputed(browser, id, prop) {
...
@@ -51,6 +51,12 @@ async function getComputed(browser, id, prop) {
return
null
return
null
}
}
async
function
getComputedStyle
(
browser
,
id
,
prop
)
{
return
browser
.
eval
(
`window.getComputedStyle(document.getElementById('
${
id
}
')).getPropertyValue('
${
prop
}
')`
)
}
async
function
getSrc
(
browser
,
id
)
{
async
function
getSrc
(
browser
,
id
)
{
const
src
=
await
browser
.
elementById
(
id
).
getAttribute
(
'src'
)
const
src
=
await
browser
.
elementById
(
id
).
getAttribute
(
'src'
)
if
(
src
)
{
if
(
src
)
{
...
@@ -586,8 +592,14 @@ describe('Image Component Tests', () => {
...
@@ -586,8 +592,14 @@ describe('Image Component Tests', () => {
it
(
'should have blurry placeholder when enabled'
,
async
()
=>
{
it
(
'should have blurry placeholder when enabled'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/blurry-placeholder'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/blurry-placeholder'
)
expect
(
html
).
toContain
(
const
$html
=
cheerio
.
load
(
html
)
'background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E")'
expect
(
$html
(
'#blurry-placeholder'
)[
0
].
attribs
.
style
).
toContain
(
`background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E")`
)
expect
(
$html
(
'#blurry-placeholder-with-lazy'
)[
0
].
attribs
.
style
).
toContain
(
`background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E")`
)
)
})
})
...
@@ -595,11 +607,33 @@ describe('Image Component Tests', () => {
...
@@ -595,11 +607,33 @@ describe('Image Component Tests', () => {
let
browser
let
browser
try
{
try
{
browser
=
await
webdriver
(
appPort
,
'/blurry-placeholder'
)
browser
=
await
webdriver
(
appPort
,
'/blurry-placeholder'
)
const
id
=
'blurry-placeholder'
const
backgroundImage
=
await
browser
.
eval
(
expect
(
`window.getComputedStyle(document.getElementById('
${
id
}
')).getPropertyValue('background-image')`
await
getComputedStyle
(
browser
,
'blurry-placeholder'
,
'background-image'
)
).
toBe
(
'none'
)
expect
(
await
getComputedStyle
(
browser
,
'blurry-placeholder-with-lazy'
,
'background-image'
)
).
toBe
(
`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' viewBox='0 0 400 400'%3E%3Cfilter id='blur' filterUnits='userSpaceOnUse' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur stdDeviation='20' edgeMode='duplicate' /%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='1 1' /%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage filter='url(%23blur)' href='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wAALCAAKAAoBAREA/8QAMwABAQEAAAAAAAAAAAAAAAAAAAcJEAABAwUAAwAAAAAAAAAAAAAFAAYRAQMEEyEVMlH/2gAIAQEAAD8Az1bLPaxhiuk0QdeCOLDtHixN2dmd2bsc5FPX7VTREX//2Q==' x='0' y='0' height='100%25' width='100%25'/%3E%3C/svg%3E")`
)
)
expect
(
backgroundImage
).
toBe
(
'none'
)
await
browser
.
eval
(
'document.getElementById("spacer").remove()'
)
expect
(
await
getComputedStyle
(
browser
,
'blurry-placeholder-with-lazy'
,
'background-image'
)
).
toBe
(
'none'
)
}
finally
{
}
finally
{
if
(
browser
)
{
if
(
browser
)
{
await
browser
.
close
()
await
browser
.
close
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment