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
79b4cb00
Unverified
Commit
79b4cb00
authored
Jun 09, 2021
by
Steven
Committed by
GitHub
Jun 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add css blur when `placeholder=blur` (#25945)
* Add css blur when `placeholder=blur` * Fix tests
parent
c6ba29da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
image.tsx
packages/next/client/image.tsx
+9
-6
static.test.js
test/integration/image-component/default/test/static.test.js
+2
-2
No files found.
packages/next/client/image.tsx
View file @
79b4cb00
...
@@ -273,12 +273,16 @@ function removePlaceholder(
...
@@ -273,12 +273,16 @@ function removePlaceholder(
// 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.
setTimeout
(()
=>
{
setTimeout
(()
=>
{
element
.
style
.
filter
=
'none'
element
.
style
.
backgroundSize
=
'none'
element
.
style
.
backgroundImage
=
'none'
element
.
style
.
backgroundImage
=
'none'
},
1500
)
},
1500
)
}
else
{
}
else
{
element
.
onload
=
()
=>
{
element
.
onload
=
()
=>
{
if
(
!
element
.
src
.
startsWith
(
'data:'
))
{
if
(
!
element
.
src
.
startsWith
(
'data:'
))
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
element
.
style
.
filter
=
'none'
element
.
style
.
backgroundSize
=
'none'
element
.
style
.
backgroundImage
=
'none'
element
.
style
.
backgroundImage
=
'none'
},
1500
)
},
1500
)
}
}
...
@@ -389,11 +393,9 @@ export default function Image({
...
@@ -389,11 +393,9 @@ export default function Image({
const
heightInt
=
getInt
(
height
)
const
heightInt
=
getInt
(
height
)
const
qualityInt
=
getInt
(
quality
)
const
qualityInt
=
getInt
(
quality
)
const
MIN_IMG_SIZE_FOR_PLACEHOLDER
=
5000
// Show blur if larger than 5000px such as 100 x 50
const
tooSmallForBlurryPlaceholder
=
const
showBlurPlaceholder
=
widthInt
&&
heightInt
&&
widthInt
*
heightInt
<
MIN_IMG_SIZE_FOR_PLACEHOLDER
placeholder
===
'blur'
&&
(
widthInt
||
0
)
*
(
heightInt
||
0
)
>
5000
const
shouldShowBlurryPlaceholder
=
placeholder
===
'blur'
&&
!
tooSmallForBlurryPlaceholder
let
wrapperStyle
:
JSX
.
IntrinsicElements
[
'div'
][
'style'
]
|
undefined
let
wrapperStyle
:
JSX
.
IntrinsicElements
[
'div'
][
'style'
]
|
undefined
let
sizerStyle
:
JSX
.
IntrinsicElements
[
'div'
][
'style'
]
|
undefined
let
sizerStyle
:
JSX
.
IntrinsicElements
[
'div'
][
'style'
]
|
undefined
...
@@ -421,8 +423,9 @@ export default function Image({
...
@@ -421,8 +423,9 @@ export default function Image({
objectFit
,
objectFit
,
objectPosition
,
objectPosition
,
...(
sho
uldShowBlurry
Placeholder
...(
sho
wBlur
Placeholder
?
{
?
{
filter
:
'blur(20px)'
,
backgroundSize
:
'cover'
,
backgroundSize
:
'cover'
,
backgroundImage
:
`url("
${
blurDataURL
}
")`
,
backgroundImage
:
`url("
${
blurDataURL
}
")`
,
}
}
...
...
test/integration/image-component/default/test/static.test.js
View file @
79b4cb00
...
@@ -39,12 +39,12 @@ const runTests = () => {
...
@@ -39,12 +39,12 @@ const runTests = () => {
})
})
it
(
'Should add a blurry placeholder to statically imported jpg'
,
async
()
=>
{
it
(
'Should add a blurry placeholder to statically imported jpg'
,
async
()
=>
{
expect
(
html
).
toContain
(
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%;background-size:cover;background-image:url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAgACAMBIgACEQEDEQH/xAAUAAEAAAAAAAAAAAAAAAAAAAAH/9oACAEBAAAAADX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAECEAAAAH//xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAEDEAAAAH//xAAdEAABAgcAAAAAAAAAAAAAAAATEhUAAwUUIzLS/9oACAEBAAE/AB0ZlUac43GqMYuo/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=")"`
`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("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAgACAMBIgACEQEDEQH/xAAUAAEAAAAAAAAAAAAAAAAAAAAH/9oACAEBAAAAADX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAECEAAAAH//xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAEDEAAAAH//xAAdEAABAgcAAAAAAAAAAAAAAAATEhUAAwUUIzLS/9oACAEBAAE/AB0ZlUac43GqMYuo/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=")"`
)
)
})
})
it
(
'Should add a blurry placeholder to statically imported png'
,
async
()
=>
{
it
(
'Should add a blurry placeholder to statically imported png'
,
async
()
=>
{
expect
(
html
).
toContain
(
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%;background-size:cover;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAQAAABuBnYAAAAATklEQVR42i2I0QmAMBQD869Q9K+IsxU6RkfoiA6T55VXDpJLJC9uUJIzcx+XFd2dXMbx8n+QpoeYDpgY66RaDA83jCUfVpK2pER1dcEUP+KfSBtXK+BpAAAAAElFTkSuQmCC")"`
`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("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAQAAABuBnYAAAAATklEQVR42i2I0QmAMBQD869Q9K+IsxU6RkfoiA6T55VXDpJLJC9uUJIzcx+XFd2dXMbx8n+QpoeYDpgY66RaDA83jCUfVpK2pER1dcEUP+KfSBtXK+BpAAAAAElFTkSuQmCC")"`
)
)
})
})
}
}
...
...
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