Unverified Commit f5e447f0 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[dev-overlay] Remove unused hydration error related code (#77929)

Also inlined some of the indirections that we no longer need.
parent fb8376a6
import {
getDefaultHydrationErrorMessage,
getHydrationErrorStackInfo,
isHydrationError,
testReactHydrationWarning,
} from '../is-hydration-error'
import {
hydrationErrorState,
getReactHydrationDiffSegments,
type HydrationErrorState,
} from './hydration-error-info'
......@@ -19,14 +19,8 @@ export function attachHydrationErrorState(error: Error) {
return
}
const reactHydrationDiffSegments = getReactHydrationDiffSegments(
error.message
)
// If the reactHydrationDiffSegments exists
// and the diff (reactHydrationDiffSegments[1]) exists
// e.g. the hydration diff log error.
if (reactHydrationDiffSegments) {
const diff = reactHydrationDiffSegments[1]
const { message, diff } = getHydrationErrorStackInfo(error.message)
if (message) {
parsedHydrationErrorState = {
...((error as any).details as HydrationErrorState),
...hydrationErrorState,
......@@ -43,7 +37,7 @@ export function attachHydrationErrorState(error: Error) {
],
// When it's hydration diff log, do not show notes section.
// This condition is only for the 1st squashed error.
notes: isHydrationWarning ? '' : reactHydrationDiffSegments[0],
notes: isHydrationWarning ? '' : message,
reactOutputComponentDiff: diff,
}
// Cache the `reactOutputComponentDiff` into hydrationErrorState.
......
import {
getHydrationErrorStackInfo,
testReactHydrationWarning,
} from '../is-hydration-error'
import { testReactHydrationWarning } from '../is-hydration-error'
export type HydrationErrorState = {
// Hydration warning template format: <message> <serverContent> <clientContent>
......@@ -55,14 +52,6 @@ const isHtmlTagsWarning = (message: string) => htmlTagsWarnings.has(message)
const isTextInTagsMismatchWarning = (msg: string) =>
textAndTagsMismatchWarnings.has(msg)
export const getReactHydrationDiffSegments = (msg: NullableText) => {
if (msg) {
const { message, diff } = getHydrationErrorStackInfo(msg)
if (message) return [message, diff]
}
return undefined
}
/**
* Patch console.error to capture hydration errors.
* If any of the knownHydrationWarnings are logged, store the message and component stack.
......
......@@ -52,7 +52,6 @@ export function testReactHydrationWarning(msg: string): boolean {
export function getHydrationErrorStackInfo(rawMessage: string): {
message: string | null
stack?: string
diff?: string
} {
rawMessage = rawMessage.replace(/^Error: /, '')
......@@ -62,7 +61,6 @@ export function getHydrationErrorStackInfo(rawMessage: string): {
if (!isReactHydrationErrorMessage(rawMessage) && !isReactHydrationWarning) {
return {
message: null,
stack: rawMessage,
diff: '',
}
}
......@@ -71,7 +69,6 @@ export function getHydrationErrorStackInfo(rawMessage: string): {
const [message, diffLog] = rawMessage.split('\n\n')
return {
message: message.trim(),
stack: '',
diff: (diffLog || '').trim(),
}
}
......@@ -83,13 +80,10 @@ export function getHydrationErrorStackInfo(rawMessage: string): {
const trimmedMessage = message.trim()
// React built-in hydration diff starts with a newline, checking if length is > 1
if (trailing && trailing.length > 1) {
const stacks: string[] = []
const diffs: string[] = []
trailing.split('\n').forEach((line) => {
if (line.trim() === '') return
if (line.trim().startsWith('at ')) {
stacks.push(line)
} else {
if (!line.trim().startsWith('at ')) {
diffs.push(line)
}
})
......@@ -97,12 +91,10 @@ export function getHydrationErrorStackInfo(rawMessage: string): {
return {
message: trimmedMessage,
diff: diffs.join('\n'),
stack: stacks.join('\n'),
}
} else {
return {
message: trimmedMessage,
stack: trailing, // without hydration diff
}
}
}
......@@ -4,7 +4,6 @@ import { useMeasureHeight } from '../../hooks/use-measure-height'
export type DialogProps = {
children?: React.ReactNode
type: 'error' | 'warning'
'aria-labelledby': string
'aria-describedby': string
className?: string
......@@ -22,7 +21,6 @@ const CSS_SELECTORS_TO_EXCLUDE_ON_CLICK_OUTSIDE = [
const Dialog: React.FC<DialogProps> = function Dialog({
children,
type,
className,
onClose,
'aria-labelledby': ariaLabelledBy,
......
......@@ -16,7 +16,6 @@ export function ErrorOverlayDialog({
return (
<div className="error-overlay-dialog-container">
<Dialog
type="error"
aria-labelledby="nextjs__container_errors_label"
aria-describedby="nextjs__container_errors_desc"
className="error-overlay-dialog-scroll"
......
......@@ -49,16 +49,10 @@ import { CollapseIcon } from '../../icons/collapse-icon'
*
*/
export function PseudoHtmlDiff({
firstContent,
secondContent,
hydrationMismatchType,
reactOutputComponentDiff,
...props
}: {
firstContent: string
secondContent: string
reactOutputComponentDiff: string
hydrationMismatchType: 'tag' | 'text' | 'text-in-tag'
} & React.HTMLAttributes<HTMLPreElement>) {
const [isDiffCollapsed, toggleCollapseHtml] = useState(true)
......
......@@ -5,10 +5,7 @@ import { RuntimeError } from './runtime-error'
import { getErrorSource } from '../../../../../shared/lib/error-source'
import { HotlinkedText } from '../components/hot-linked-text'
import { PseudoHtmlDiff } from './runtime-error/component-stack-pseudo-html'
import {
type HydrationErrorState,
getHydrationWarningType,
} from '../../../errors/hydration-error-info'
import type { HydrationErrorState } from '../../../errors/hydration-error-info'
import {
isConsoleError,
getConsoleErrorType,
......@@ -131,7 +128,6 @@ export function Errors({
const [warningTemplate, serverContent, clientContent] =
errorDetails.warning || [null, '', '']
const hydrationErrorType = getHydrationWarningType(warningTemplate)
const hydrationWarning = warningTemplate
? warningTemplate
.replace('%s', serverContent)
......@@ -193,9 +189,6 @@ export function Errors({
!!errorDetails.reactOutputComponentDiff) ? (
<PseudoHtmlDiff
className="nextjs__container_errors__component-stack"
hydrationMismatchType={hydrationErrorType}
firstContent={serverContent}
secondContent={clientContent}
reactOutputComponentDiff={errorDetails.reactOutputComponentDiff || ''}
/>
) : null}
......
......@@ -15,25 +15,18 @@ type Story = StoryObj<typeof PseudoHtmlDiff>
export const TextMismatch: Story = {
args: {
firstContent: 'Server rendered content',
secondContent: 'Client rendered content',
hydrationMismatchType: 'text',
reactOutputComponentDiff: undefined,
},
}
export const TextInTagMismatch: Story = {
args: {
firstContent: 'Mismatched content',
secondContent: 'p',
hydrationMismatchType: 'text-in-tag',
reactOutputComponentDiff: undefined,
},
}
export const ReactUnifiedMismatch: Story = {
args: {
hydrationMismatchType: 'tag',
reactOutputComponentDiff: `<Page>
<Layout>
<div>
......
import { parse } from 'next/dist/compiled/stacktrace-parser'
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
import {
getHydrationErrorStackInfo,
isReactHydrationErrorMessage,
} from '../../is-hydration-error'
const regexNextStatic = /\/_next(\/static\/.+)/
export function parseStack(stack: string | undefined): StackFrame[] {
if (!stack) return []
const messageAndStack = stack.replace(/^Error: /, '')
if (isReactHydrationErrorMessage(messageAndStack)) {
const { stack: parsedStack } = getHydrationErrorStackInfo(messageAndStack)
if (parsedStack) {
stack = parsedStack
}
}
// throw away eval information that stacktrace-parser doesn't support
// adapted from https://github.com/stacktracejs/error-stack-parser/blob/9f33c224b5d7b607755eb277f9d51fcdb7287e24/error-stack-parser.js#L59C33-L59C62
......
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