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
18dc09bf
Unverified
Commit
18dc09bf
authored
Feb 28, 2023
by
Steven
Committed by
GitHub
Feb 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: should not warn when image unmounts (#46567)
- Fixes #40762 ---------
parent
9edf2d3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
1 deletion
+36
-1
image.tsx
packages/next/src/client/image.tsx
+1
-1
should-not-warn-unmount.js
...n/next-image-new/default/pages/should-not-warn-unmount.js
+25
-0
index.test.ts
test/integration/next-image-new/default/test/index.test.ts
+10
-0
No files found.
packages/next/src/client/image.tsx
View file @
18dc09bf
...
...
@@ -276,7 +276,7 @@ function handleLoading(
img
[
'data-loaded-src'
]
=
src
const
p
=
'decode'
in
img
?
img
.
decode
()
:
Promise
.
resolve
()
p
.
catch
(()
=>
{}).
then
(()
=>
{
if
(
!
img
.
parent
Node
)
{
if
(
!
img
.
parent
Element
||
!
img
.
isConnected
)
{
// Exit early in case of race condition:
// - onload() is called
// - decode() is called but incomplete
...
...
test/integration/next-image-new/default/pages/should-not-warn-unmount.js
0 → 100644
View file @
18dc09bf
import
Image
from
'next/image'
import
{
useEffect
,
useState
}
from
'react'
export
default
function
Home
()
{
const
[
displayImage
,
setDisplayImage
]
=
useState
(
true
)
useEffect
(()
=>
{
// This will cause the image to unmount.
// See https://github.com/vercel/next.js/issues/40762
setDisplayImage
(
false
)
},
[])
return
(
<
main
>
<
h1
>
Should
not
warn
on
unmount
<
/h1
>
<
section
>
{
displayImage
?
(
<
div
style
=
{{
position
:
'relative'
,
width
:
10
,
height
:
10
}}
>
<
Image
priority
fill
src
=
"/test.jpg"
alt
=
"alt"
sizes
=
"10px"
/>
<
/div
>
)
:
null
}
<
/section
>
<
/main
>
)
}
test/integration/next-image-new/default/test/index.test.ts
View file @
18dc09bf
...
...
@@ -1167,6 +1167,16 @@ function runTests(mode) {
'Image with src "/wide.png" has "fill" but is missing "sizes" prop. Please add it to improve page performance. Read more:'
)
})
it
(
'should not log warnings when image unmounts'
,
async
()
=>
{
browser
=
await
webdriver
(
appPort
,
'/should-not-warn-unmount'
)
await
waitFor
(
1000
)
const
warnings
=
(
await
browser
.
log
(
'browser'
))
.
map
((
log
)
=>
log
.
message
)
.
join
(
'
\
n'
)
expect
(
warnings
).
not
.
toContain
(
'Image with src "/test.jpg" has "fill" and parent element'
)
})
}
})
// Tests that use the `unsized` attribute:
...
...
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