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
fbe971c1
Unverified
Commit
fbe971c1
authored
Feb 04, 2025
by
Jiachi Liu
Committed by
GitHub
Feb 04, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish hydration errors (#75632)
parent
477eaf0e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
92 deletions
+100
-92
code-frame.tsx
...xperimental/internal/components/code-frame/code-frame.tsx
+3
-1
errors.tsx
...t-dev-overlay/_experimental/internal/container/errors.tsx
+3
-5
component-stack-pseudo-html.tsx
...l/container/runtime-error/component-stack-pseudo-html.tsx
+94
-86
No files found.
packages/next/src/client/components/react-dev-overlay/_experimental/internal/components/code-frame/code-frame.tsx
View file @
fbe971c1
...
@@ -111,6 +111,9 @@ export const CODE_FRAME_STYLES = css`
...
@@ -111,6 +111,9 @@ export const CODE_FRAME_STYLES = css`
font-family: var(--font-stack-monospace);
font-family: var(--font-stack-monospace);
font-size: 12px;
font-size: 12px;
line-height: 16px;
line-height: 16px;
margin: var(--size-4) var(--size-4) var(--size-2);
border: 1px solid var(--color-gray-400);
border-radius: var(--size-2);
}
}
[data-nextjs-codeframe] pre {
[data-nextjs-codeframe] pre {
...
@@ -118,7 +121,6 @@ export const CODE_FRAME_STYLES = css`
...
@@ -118,7 +121,6 @@ export const CODE_FRAME_STYLES = css`
}
}
.code-frame-header {
.code-frame-header {
border-top: 1px solid var(--color-gray-400);
border-bottom: 1px solid var(--color-gray-400);
border-bottom: 1px solid var(--color-gray-400);
}
}
...
...
packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/errors.tsx
View file @
fbe971c1
...
@@ -203,14 +203,12 @@ export const styles = css`
...
@@ -203,14 +203,12 @@ export const styles = css`
bottom: calc(var(--size-gap-double) * 4.5);
bottom: calc(var(--size-gap-double) * 4.5);
}
}
p.nextjs__container_errors__link {
p.nextjs__container_errors__link {
color: var(--color-text-color-red-1);
font-size: 14px;
font-weight: 600;
font-size: 15px;
}
}
p.nextjs__container_errors__notes {
p.nextjs__container_errors__notes {
color: var(--color-stack-notes);
color: var(--color-stack-notes);
font-
weight: 600
;
font-
size: 14px
;
font-size: 15px
;
line-height: 1.5
;
}
}
.nextjs-container-errors-body > h2:not(:first-child) {
.nextjs-container-errors-body > h2:not(:first-child) {
margin-top: calc(var(--size-gap-double) + var(--size-gap));
margin-top: calc(var(--size-gap-double) + var(--size-gap));
...
...
packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/runtime-error/component-stack-pseudo-html.tsx
View file @
fbe971c1
...
@@ -94,18 +94,12 @@ export function PseudoHtmlDiff({
...
@@ -94,18 +94,12 @@ export function PseudoHtmlDiff({
diffHtmlStack
.
push
(
diffHtmlStack
.
push
(
<
span
<
span
key=
{
'comp-diff'
+
index
}
key=
{
'comp-diff'
+
index
}
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
{
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
{
sign
===
'+'
?
'add'
:
'remove'
sign
===
'+'
?
'add'
:
'remove'
}
}
>
>
{
sign
===
'+'
?
<
PlusIcon
/>
:
<
MinusIcon
/>
}
<
span
>
<
span
className=
{
isHtmlCollapsed
?
'error-overlay-hydration-error-collapsed'
:
''
}
>
{
/* Slice 2 spaces for the icon */
}
{
/* Slice 2 spaces for the icon */
}
{
spaces
.
slice
(
2
)
}
{
spaces
.
slice
(
2
)
}
{
trimmedLine
}
{
trimmedLine
}
...
@@ -121,7 +115,10 @@ export function PseudoHtmlDiff({
...
@@ -121,7 +115,10 @@ export function PseudoHtmlDiff({
if
(
isUserLandComponent
||
trimmedLine
===
'...'
)
{
if
(
isUserLandComponent
||
trimmedLine
===
'...'
)
{
currentComponentIndex
--
currentComponentIndex
--
componentStacks
.
push
(
componentStacks
.
push
(
<
span
key=
{
'comp-diff'
+
index
}
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
key=
{
'comp-diff'
+
index
}
>
{
spaces
}
{
spaces
}
{
trimmedLine
}
{
trimmedLine
}
{
'
\
n'
}
{
'
\
n'
}
...
@@ -129,7 +126,10 @@ export function PseudoHtmlDiff({
...
@@ -129,7 +126,10 @@ export function PseudoHtmlDiff({
)
)
}
else
if
(
!
isHtmlCollapsed
)
{
}
else
if
(
!
isHtmlCollapsed
)
{
componentStacks
.
push
(
componentStacks
.
push
(
<
span
key=
{
'comp-diff'
+
index
}
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
key=
{
'comp-diff'
+
index
}
>
{
spaces
}
{
spaces
}
{
trimmedLine
}
{
trimmedLine
}
{
'
\
n'
}
{
'
\
n'
}
...
@@ -139,7 +139,10 @@ export function PseudoHtmlDiff({
...
@@ -139,7 +139,10 @@ export function PseudoHtmlDiff({
}
else
if
(
!
isHtmlCollapsed
)
{
}
else
if
(
!
isHtmlCollapsed
)
{
// In general, if it's not collapsed, show the whole diff
// In general, if it's not collapsed, show the whole diff
componentStacks
.
push
(
componentStacks
.
push
(
<
span
key=
{
'comp-diff'
+
index
}
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
key=
{
'comp-diff'
+
index
}
>
{
spaces
}
{
spaces
}
{
trimmedLine
}
{
trimmedLine
}
{
'
\
n'
}
{
'
\
n'
}
...
@@ -200,21 +203,16 @@ export function PseudoHtmlDiff({
...
@@ -200,21 +203,16 @@ export function PseudoHtmlDiff({
if
((
isHtmlTagsWarning
&&
isAdjacentTag
)
||
isLastFewFrames
)
{
if
((
isHtmlTagsWarning
&&
isAdjacentTag
)
||
isLastFewFrames
)
{
const
codeLine
=
(
const
codeLine
=
(
<
span
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
{
...
(
isHighlightedTag
?
{
'
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
--
error
':
true
,
}
:
undefined
)}
>
{
spaces
}
{
spaces
}
<
span
<
span
{
...
adjProps
}
>
{
`<${component}>\n`
}
</
span
>
{
...
adjProps
}
{
...
{
...
(
isHighlightedTag
?
{
'
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
tag
-
error
':
true
,
}
:
undefined
),
}}
>
{
`<${component}>\n`
}
</
span
>
</
span
>
</
span
>
)
)
lastText
=
component
lastText
=
component
...
@@ -241,7 +239,11 @@ export function PseudoHtmlDiff({
...
@@ -241,7 +239,11 @@ export function PseudoHtmlDiff({
if
(
!
isHtmlCollapsed
||
isLastFewFrames
)
{
if
(
!
isHtmlCollapsed
||
isLastFewFrames
)
{
nestedHtmlStack
.
push
(
nestedHtmlStack
.
push
(
<
span
{
...
adjProps
}
key=
{
nestedHtmlStack
.
length
}
>
<
span
{
...
adjProps
}
key=
{
nestedHtmlStack
.
length
}
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
>
{
spaces
}
{
spaces
}
{
'<'
+
component
+
'>
\
n'
}
{
'<'
+
component
+
'>
\
n'
}
</
span
>
</
span
>
...
@@ -249,7 +251,11 @@ export function PseudoHtmlDiff({
...
@@ -249,7 +251,11 @@ export function PseudoHtmlDiff({
}
else
if
(
isHtmlCollapsed
&&
lastText
!==
'...'
)
{
}
else
if
(
isHtmlCollapsed
&&
lastText
!==
'...'
)
{
lastText
=
'...'
lastText
=
'...'
nestedHtmlStack
.
push
(
nestedHtmlStack
.
push
(
<
span
{
...
adjProps
}
key=
{
nestedHtmlStack
.
length
}
>
<
span
{
...
adjProps
}
key=
{
nestedHtmlStack
.
length
}
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
>
{
spaces
}
{
spaces
}
{
'...
\
n'
}
{
'...
\
n'
}
</
span
>
</
span
>
...
@@ -265,10 +271,16 @@ export function PseudoHtmlDiff({
...
@@ -265,10 +271,16 @@ export function PseudoHtmlDiff({
// hydration type is "text", represent [server content, client content]
// hydration type is "text", represent [server content, client content]
wrappedCodeLine
=
(
wrappedCodeLine
=
(
<
Fragment
key=
{
nestedHtmlStack
.
length
}
>
<
Fragment
key=
{
nestedHtmlStack
.
length
}
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
"remove"
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
"remove"
>
{
spaces
+
`"${firstContent}"\n`
}
{
spaces
+
`"${firstContent}"\n`
}
</
span
>
</
span
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
"add"
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
"add"
>
{
spaces
+
`"${secondContent}"\n`
}
{
spaces
+
`"${secondContent}"\n`
}
</
span
>
</
span
>
</
Fragment
>
</
Fragment
>
...
@@ -277,10 +289,16 @@ export function PseudoHtmlDiff({
...
@@ -277,10 +289,16 @@ export function PseudoHtmlDiff({
// hydration type is "text-in-tag", represent [parent tag, mismatch content]
// hydration type is "text-in-tag", represent [parent tag, mismatch content]
wrappedCodeLine
=
(
wrappedCodeLine
=
(
<
Fragment
key=
{
nestedHtmlStack
.
length
}
>
<
Fragment
key=
{
nestedHtmlStack
.
length
}
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
tag
-
adjacent
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
tag
-
adjacent
>
{
spaces
+
`<${secondContent}>\n`
}
{
spaces
+
`<${secondContent}>\n`
}
</
span
>
</
span
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
"remove"
>
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
--
diff=
"remove"
>
{
spaces
+
` "${firstContent}"\n`
}
{
spaces
+
` "${firstContent}"\n`
}
</
span
>
</
span
>
</
Fragment
>
</
Fragment
>
...
@@ -318,92 +336,82 @@ export function PseudoHtmlDiff({
...
@@ -318,92 +336,82 @@ export function PseudoHtmlDiff({
)
)
}
}
function
PlusIcon
()
{
return
(
<
svg
width=
"16"
height=
"16"
viewBox=
"0 0 16 16"
fill=
"none"
xmlns=
"http://www.w3.org/2000/svg"
className=
"error-overlay-hydration-error-diff-plus-icon"
>
<
path
fillRule=
"evenodd"
clipRule=
"evenodd"
d=
"M7.25 8.75V12H8.75V8.75H12V7.25H8.75V4H7.25V7.25H4V8.75H7.25Z"
fill=
"currentColor"
/>
</
svg
>
)
}
function
MinusIcon
()
{
return
(
<
svg
width=
"16"
height=
"16"
viewBox=
"0 0 16 16"
fill=
"none"
xmlns=
"http://www.w3.org/2000/svg"
className=
"error-overlay-hydration-error-diff-minus-icon"
>
<
path
fillRule=
"evenodd"
clipRule=
"evenodd"
d=
"M12 8.75H4V7.25H12V8.75Z"
fill=
"currentColor"
/>
</
svg
>
)
}
export
const
PSEUDO_HTML_DIFF_STYLES
=
css
`
export
const
PSEUDO_HTML_DIFF_STYLES
=
css
`
[data-nextjs-container-errors-pseudo-html] {
[data-nextjs-container-errors-pseudo-html] {
border-top: 1px solid var(--color-gray-400);
padding: var(--size-3) 0;
margin: var(--size-2) var(--size-4) var(--size-4);
border: 1px solid var(--color-gray-400);
background: var(--color-background-200);
background: var(--color-background-200);
color: var(--color-syntax-constant);
color: var(--color-syntax-constant);
font-family: var(--font-stack-monospace);
font-family: var(--font-stack-monospace);
font-size: var(--size-font-smaller);
font-size: var(--size-font-smaller);
line-height: var(--size-4);
line-height: var(--size-4);
border-radius: var(--size-2);
}
[data-nextjs-container-errors-pseudo-html-line] {
display: inline-block;
width: 100%;
padding-left: var(--size-10);
line-height: calc(5 / 3);
}
[data-nextjs-container-errors-pseudo-html-line--error] {
background: var(--color-amber-300);
font-weight: bold;
}
[data-nextjs-container-errors-pseudo-html-line--error]::before {
content: '>';
color: var(--color-red-900);
float: left;
width: 0;
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
}
}
[data-nextjs-container-errors-pseudo-html-collapse] {
[data-nextjs-container-errors-pseudo-html-collapse] {
all: unset;
all: unset;
padding: var(--size-2
);
margin-left: var(--size-3
);
&:focus {
&:focus {
outline: none;
outline: none;
}
}
}
}
[data-nextjs-container-errors-pseudo-html--diff] {
width: fit-content;
}
[data-nextjs-container-errors-pseudo-html--diff='add'] {
[data-nextjs-container-errors-pseudo-html--diff='add'] {
background: var(--color-green-300);
background: var(--color-green-300);
}
}
[data-nextjs-container-errors-pseudo-html--diff='add']::before {
content: '+';
color: var(--color-green-900);
float: left;
width: 0;
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
}
[data-nextjs-container-errors-pseudo-html--diff='remove'] {
[data-nextjs-container-errors-pseudo-html--diff='remove'] {
background: var(--color-red-300);
background: var(--color-red-300);
}
}
[data-nextjs-container-errors-pseudo-html--tag-error] {
[data-nextjs-container-errors-pseudo-html--diff='remove']::before {
background: var(--color-red-300);
content: '-';
font-weight: bold;
color: var(--color-red-900);
float: left;
width: 0;
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
}
}
/* hide but text are still accessible in DOM */
${
/* hide but text are still accessible in DOM */
''
}
[data-nextjs-container-errors-pseudo-html--hint] {
[data-nextjs-container-errors-pseudo-html--hint] {
display: inline-block;
display: inline-block;
font-size: 0;
font-size: 0;
height: 0;
}
}
[data-nextjs-container-errors-pseudo-html--tag-adjacent='false'] {
[data-nextjs-container-errors-pseudo-html--tag-adjacent='false'] {
color: var(--color-accents-1);
color: var(--color-accents-1);
}
}
[data-nextjs-container-errors-pseudo-html] > pre > code > span {
display: block;
padding: var(--size-1) var(--size-4);
}
.nextjs__container_errors__component-stack {
.nextjs__container_errors__component-stack {
margin: 0;
margin: 0;
}
}
.error-overlay-hydration-error-collapsed {
.nextjs__container_errors__component-stack code {
padding-left: var(--size-4);
display: block;
width: 100%;
white-space: pre-wrap;
}
}
.error-overlay-hydration-error-diff-plus-icon {
.error-overlay-hydration-error-diff-plus-icon {
color: var(--color-green-900);
color: var(--color-green-900);
...
...
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