Commit 679c62cc authored by Jiachi Liu's avatar Jiachi Liu

drop component stacks

parent 547ef944
......@@ -137,8 +137,8 @@ export function Errors({
: undefined
const diffContent = (errorDetails.reactOutputComponentDiff || '')
.trim()
.replace(/\.\.\.\s*/, '')
// .trim()
// .replace(/\.\.\.\s*/, '')
const showHydrationDiff = Boolean(
hydrationWarning &&
// activeError.componentStackFrames?.length ||
......@@ -193,7 +193,6 @@ export function Errors({
<PseudoHtmlDiff
className="nextjs__container_errors__component-stack"
hydrationMismatchType={hydrationErrorType}
componentStackFrames={activeError.componentStackFrames || []}
firstContent={serverContent}
secondContent={clientContent}
reactOutputComponentDiff={diffContent}
......
......@@ -13,28 +13,8 @@ const meta: Meta<typeof PseudoHtmlDiff> = {
export default meta
type Story = StoryObj<typeof PseudoHtmlDiff>
const sampleComponentStack = [
{
component: 'div',
canOpenInEditor: false,
},
{
component: 'article',
canOpenInEditor: false,
},
{
component: 'main',
canOpenInEditor: false,
},
{
component: 'Home',
canOpenInEditor: false,
},
]
export const TextMismatch: Story = {
args: {
componentStackFrames: sampleComponentStack,
firstContent: 'Server rendered content',
secondContent: 'Client rendered content',
hydrationMismatchType: 'text',
......@@ -44,7 +24,6 @@ export const TextMismatch: Story = {
export const TextInTagMismatch: Story = {
args: {
componentStackFrames: sampleComponentStack,
firstContent: 'Mismatched content',
secondContent: 'p',
hydrationMismatchType: 'text-in-tag',
......@@ -54,7 +33,6 @@ export const TextInTagMismatch: Story = {
export const ReactUnifiedMismatch: Story = {
args: {
componentStackFrames: sampleComponentStack,
hydrationMismatchType: 'tag',
reactOutputComponentDiff: `<Page>
<Layout>
......
......@@ -24,15 +24,6 @@ export const PSEUDO_HTML_DIFF_STYLES = css`
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-button] {
all: unset;
margin-left: var(--size-3);
......@@ -43,24 +34,23 @@ export const PSEUDO_HTML_DIFF_STYLES = css`
[data-nextjs-container-errors-pseudo-html--diff='add'] {
background: var(--color-green-300);
}
[data-nextjs-container-errors-pseudo-html--diff='add']::before {
content: '+';
color: var(--color-green-900);
float: left;
width: 0;
[data-nextjs-container-errors-pseudo-html-line-sign] {
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
margin-right: var(--size-6);
}
[data-nextjs-container-errors-pseudo-html--diff='add'] [data-nextjs-container-errors-pseudo-html-line-sign] {
color: var(--color-green-900);
}
[data-nextjs-container-errors-pseudo-html--diff='remove'] {
background: var(--color-red-300);
}
[data-nextjs-container-errors-pseudo-html--diff='remove']::before {
content: '-';
[data-nextjs-container-errors-pseudo-html--diff='remove'] [data-nextjs-container-errors-pseudo-html-line-sign] {
color: var(--color-red-900);
float: left;
width: 0;
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
margin-right: var(--size-6);
}
[data-nextjs-container-errors-pseudo-html-line--error] [data-nextjs-container-errors-pseudo-html-line-sign] {
color: var(--color-red-900);
}
${/* hide but text are still accessible in DOM */ ''}
[data-nextjs-container-errors-pseudo-html--hint] {
......
import { useMemo, useState } from 'react'
import type { ComponentStackFrame } from '../internal/helpers/parse-component-stack'
import { CollapseIcon } from '../internal/icons/CollapseIcon'
/**
......@@ -51,14 +50,12 @@ import { CollapseIcon } from '../internal/icons/CollapseIcon'
*
*/
export function PseudoHtmlDiff({
componentStackFrames,
firstContent,
secondContent,
hydrationMismatchType,
reactOutputComponentDiff,
...props
}: {
componentStackFrames: ComponentStackFrame[]
firstContent: string
secondContent: string
reactOutputComponentDiff: string
......@@ -68,22 +65,19 @@ export function PseudoHtmlDiff({
const htmlComponents = useMemo(() => {
const componentStacks: React.ReactNode[] = []
let currentComponentIndex = componentStackFrames.length - 1
const reactComponentDiffLines = reactOutputComponentDiff!.split('\n')
reactComponentDiffLines.forEach((line, index) => {
let trimmedLine = line.trim()
const isDiffLine = trimmedLine[0] === '+' || trimmedLine[0] === '-'
const isHighlightedLine = trimmedLine[0] === '>'
const spaces = ' '.repeat(
line.length - trimmedLine.slice(1).trim().length
)
if (isHighlightedLine) {
trimmedLine = trimmedLine.slice(2).trim() // trim spaces after sign
}
const sign = isHighlightedLine || isDiffLine ? trimmedLine[0] : ''
const [prefix, suffix] = (isHighlightedLine || isDiffLine)
? line.split(sign, 2)
: [line, '']
if (isDiffLine) {
const sign = trimmedLine[0]
trimmedLine = trimmedLine.slice(1).trim() // trim spaces after sign
componentStacks.push(
<span
key={'comp-diff' + index}
......@@ -94,69 +88,37 @@ export function PseudoHtmlDiff({
>
<span>
{/* Slice 2 spaces for the icon */}
{spaces}
{trimmedLine}
{prefix}
<span data-nextjs-container-errors-pseudo-html-line-sign>{sign}</span>
{suffix}
{'\n'}
</span>
</span>
)
} else if (currentComponentIndex >= 0) {
const isUserLandComponent = trimmedLine.startsWith(
'<' + componentStackFrames[currentComponentIndex].component
)
// If it's matched userland component or it's ... we will keep the component stack in diff
if (isUserLandComponent || trimmedLine === '...') {
currentComponentIndex--
componentStacks.push(
<span
data-nextjs-container-errors-pseudo-html-line
key={'comp-diff' + index}
{...(isHighlightedLine
? {
'data-nextjs-container-errors-pseudo-html-line--error':
true,
}
: undefined)}
>
{spaces}
{trimmedLine}
{'\n'}
</span>
)
} else {
componentStacks.push(
<span
data-nextjs-container-errors-pseudo-html-line
key={'comp-diff' + index}
{...(isHighlightedLine
? {
'data-nextjs-container-errors-pseudo-html-line--error':
true,
}
: undefined)}
>
{spaces}
{trimmedLine}
{'\n'}
</span>
)
}
} else {
// In general, if it's not collapsed, show the whole diff
componentStacks.push(
<span
data-nextjs-container-errors-pseudo-html-line
key={'comp-diff' + index}
{...(isHighlightedLine
? {
'data-nextjs-container-errors-pseudo-html-line--error':
true,
}
: undefined
)}
>
{spaces}
{trimmedLine}
{prefix}
<span data-nextjs-container-errors-pseudo-html-line-sign>{sign}</span>
{suffix}
{'\n'}
</span>
)
}
})
return componentStacks
}, [componentStackFrames, reactOutputComponentDiff])
}, [reactOutputComponentDiff])
return (
<div
......
......@@ -297,25 +297,10 @@ export function Errors({
: null
const diffContent = (errorDetails.reactOutputComponentDiff || '')
.trim()
.replace(/\.\.\.\s*/, '')
const showHydrationDiff = Boolean(
hydrationWarning &&
// activeError.componentStackFrames?.length ||
!!diffContent
hydrationWarning && !!diffContent
)
// const componentStackNames: string[] = activeError.componentStackFrames
// ? activeError.componentStackFrames.map((f) => f.component)
// : ((errorDetails.componentStack || '')
// .split('\n')
// .map((line) => {
// // at ComponentName (location)
// const match = line.trim().match(/at ([\w]+)/)
// return match ? match[1] : ''
// })
// .filter(Boolean) as string[])
return (
<Overlay>
<Dialog
......@@ -402,7 +387,6 @@ export function Errors({
<PseudoHtmlDiff
className="nextjs__container_errors__component-stack"
hydrationMismatchType={hydrationErrorType}
componentStackFrames={activeError.componentStackFrames || []}
firstContent={serverContent}
secondContent={clientContent}
reactOutputComponentDiff={diffContent}
......
......@@ -76,7 +76,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await session.assertHasRedbox()
expect(await getRedboxTotalErrorCount(browser)).toBe(isReact18 ? 2 : 1)
await session.openRedbox()
if (isReact18) {
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Text content did not match. Server: "server" Client: "client""`
......@@ -204,6 +205,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
)
})
await session.openRedbox()
const pseudoHtml = await session.getRedboxComponentStack()
if (isTurbopack) {
if (isReact18) {
......@@ -842,7 +844,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await retry(async () => {
expect(await getRedboxTotalErrorCount(browser)).toBe(isReact18 ? 3 : 1)
})
await session.openRedbox()
const description = await session.getRedboxDescription()
if (isReact18) {
expect(description).toMatchInlineSnapshot(
......@@ -878,7 +881,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
}
})
it('should only show one hydration error when bad nesting happened - div > tr', async () => {
it.only('should only show one hydration error when bad nesting happened - div > tr', async () => {
await using sandbox = await createSandbox(
next,
new Map([
......@@ -897,7 +900,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await retry(async () => {
expect(await getRedboxTotalErrorCount(browser)).toBe(isReact18 ? 3 : 1)
})
await session.openRedbox()
const description = await session.getRedboxDescription()
if (isReact18) {
expect(description).toMatchInlineSnapshot(
......@@ -977,7 +981,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await retry(async () => {
expect(await getRedboxTotalErrorCount(browser)).toBe(isReact18 ? 3 : 1)
})
await session.openRedbox()
const description = await session.getRedboxDescription()
if (isReact18) {
expect(description).toMatchInlineSnapshot(
......@@ -1125,12 +1130,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
const { session, browser } = sandbox
await session.assertHasRedbox()
await retry(async () => {
await expect(await getRedboxTotalErrorCount(browser)).toBe(
expect(await getRedboxTotalErrorCount(browser)).toBe(
// This case only hit 2 errors in React 18
isReact18 ? 2 : 1
)
})
await session.openRedbox()
const pseudoHtml = await session.getRedboxComponentStack()
if (isTurbopack) {
// FIXME: Should not fork on Turbopack i.e. match the snapshot in the else-branch
......
export default function Page() {
return <p>hello world</p>
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
{isClient && 'second'}
<footer className="3" />
</div>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
const nextConfig = {
experimental: {
// newDevOverlay: true,
},
}
module.exports = nextConfig
// export default function Page() {
// return <p>hello world</p>
// }
export default function Page() {
return <p>hello world</p>
}
return <div><tr></tr></div>
}
\ No newline at end of file
......@@ -1292,8 +1292,7 @@ export async function getRedboxComponentStack(
'[data-nextjs-container-errors-pseudo-html] code',
30000
)
// TODO: the type for elementsByCss is incorrect
const componentStackFrameElements: any = await browser.elementsByCss(
const componentStackFrameElements = await browser.elementsByCss(
'[data-nextjs-container-errors-pseudo-html] code'
)
const componentStackFrameTexts = await Promise.all(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment