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
16de4b55
Commit
16de4b55
authored
Sep 12, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[devtool] fix overlay styles are missing (#83721)
parent
39c3cd62
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
31 deletions
+86
-31
devtool-style-inject.js
...src/build/webpack/loaders/devtool/devtool-style-inject.js
+39
-31
index.test.tsx
test/development/error-overlay/index.test.tsx
+24
-0
_app.tsx
test/development/error-overlay/pages/_app.tsx
+5
-0
_document.tsx
test/development/error-overlay/pages/_document.tsx
+13
-0
hydration-error.tsx
test/development/error-overlay/pages/hydration-error.tsx
+5
-0
No files found.
packages/next/src/build/webpack/loaders/devtool/devtool-style-inject.js
View file @
16de4b55
...
...
@@ -85,42 +85,50 @@ function startObservingForPortal() {
// Set up MutationObserver to watch for the portal element
const
observer
=
new
MutationObserver
((
mutations
)
=>
{
if
(
mutations
.
length
===
0
||
mutations
[
0
].
addedNodes
.
length
===
0
)
{
if
(
mutations
.
length
===
0
)
{
return
}
// Check if mutation is script[data-nextjs-dev-overlay] tag, which is the
// parent of the nextjs-portal element
const
mutationNode
=
mutations
[
0
].
addedNodes
[
0
]
let
portalNode
=
null
if
(
// app router: body > script[data-nextjs-dev-overlay] > nextjs-portal
mutationNode
.
tagName
===
'SCRIPT'
&&
mutationNode
.
getAttribute
(
'data-nextjs-dev-overlay'
)
)
{
portalNode
=
mutationNode
.
firstChild
}
else
if
(
// pages router: body > nextjs-portal
mutationNode
.
tagName
===
'NEXTJS-PORTAL'
)
{
portalNode
=
mutationNode
}
if
(
!
portalNode
)
{
return
}
// Wait until shadow root is available
const
checkShadowRoot
=
()
=>
{
if
(
getShadowRoot
())
{
flushCachedElements
()
observer
.
disconnect
()
cache
.
isObserving
=
false
}
else
{
// Try again after a short delay
setTimeout
(
checkShadowRoot
,
20
)
// Check all mutations and all added nodes
for
(
const
mutation
of
mutations
)
{
if
(
mutation
.
addedNodes
.
length
===
0
)
continue
for
(
const
addedNode
of
mutation
.
addedNodes
)
{
if
(
addedNode
.
nodeType
!==
Node
.
ELEMENT_NODE
)
continue
const
mutationNode
=
addedNode
let
portalNode
=
null
if
(
// app router: body > script[data-nextjs-dev-overlay] > nextjs-portal
mutationNode
.
tagName
===
'SCRIPT'
&&
mutationNode
.
getAttribute
(
'data-nextjs-dev-overlay'
)
)
{
portalNode
=
mutationNode
.
firstChild
}
else
if
(
// pages router: body > nextjs-portal
mutationNode
.
tagName
===
'NEXTJS-PORTAL'
)
{
portalNode
=
mutationNode
}
if
(
portalNode
)
{
// Wait until shadow root is available
const
checkShadowRoot
=
()
=>
{
if
(
getShadowRoot
())
{
flushCachedElements
()
observer
.
disconnect
()
cache
.
isObserving
=
false
}
else
{
// Try again after a short delay
setTimeout
(
checkShadowRoot
,
20
)
}
}
checkShadowRoot
()
return
// Exit early once we find a portal
}
}
}
checkShadowRoot
()
})
observer
.
observe
(
document
.
body
,
{
...
...
test/development/error-overlay/index.test.tsx
View file @
16de4b55
...
...
@@ -54,4 +54,28 @@ describe('DevErrorOverlay', () => {
expect
(
request
.
status
).
toBe
(
200
)
}
})
it
(
'should load dev overlay styles successfully'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/hydration-error'
)
await
assertHasRedbox
(
browser
)
const
redbox
=
browser
.
locateRedbox
()
// check the data-nextjs-dialog-header="true" DOM element styles under redbox is applied
const
dialogHeader
=
redbox
.
locator
(
'[data-nextjs-dialog-header="true"]'
)
expect
(
await
dialogHeader
.
isVisible
()).
toBe
(
true
)
// get computed styles
const
computedStyles
=
await
dialogHeader
.
evaluate
((
element
)
=>
{
return
window
.
getComputedStyle
(
element
)
})
const
styles
=
{
backgroundColor
:
computedStyles
.
backgroundColor
,
color
:
computedStyles
.
color
,
}
expect
(
styles
).
toEqual
({
backgroundColor
:
'rgba(0, 0, 0, 0)'
,
color
:
'rgb(117, 117, 117)'
,
})
})
})
test/development/error-overlay/pages/_app.tsx
0 → 100644
View file @
16de4b55
import
type
{
AppProps
}
from
'next/app'
export
default
function
App
({
Component
,
pageProps
}:
AppProps
)
{
return
<
Component
{
...
pageProps
}
/>
}
test/development/error-overlay/pages/_document.tsx
0 → 100644
View file @
16de4b55
import
{
Html
,
Head
,
Main
,
NextScript
}
from
'next/document'
export
default
function
Document
()
{
return
(
<
Html
lang=
"en"
>
<
Head
/>
<
body
>
<
Main
/>
<
NextScript
/>
</
body
>
</
Html
>
)
}
test/development/error-overlay/pages/hydration-error.tsx
0 → 100644
View file @
16de4b55
export
default
function
Home
()
{
return
(
<
div
>
{
typeof
window
===
'undefined'
?
<
p
>
Server
</
p
>
:
<
p
>
Client
</
p
>
}
</
div
>
)
}
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