Skip to content

Commit db85f72

Browse files
committed
[dev-overlay] Inject getSquashedHydrationErrorDetails implementation
1 parent 02ab7ed commit db85f72

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

packages/next/src/client/components/react-dev-overlay/app/app-dev-overlay.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ function ReplaySsrOnlyErrors({
7272
return null
7373
}
7474

75+
function getSquashedHydrationErrorDetails() {
76+
// We don't squash hydration errors in the App Router.
77+
return null
78+
}
79+
7580
export function AppDevOverlay({
7681
state,
7782
dispatch,
@@ -99,7 +104,11 @@ export function AppDevOverlay({
99104
<>
100105
{/* Fonts can only be loaded outside the Shadow DOM. */}
101106
<FontStyles />
102-
<DevOverlay state={state} dispatch={dispatch} />
107+
<DevOverlay
108+
state={state}
109+
dispatch={dispatch}
110+
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
111+
/>
103112
</>
104113
</>
105114
)

packages/next/src/client/components/react-dev-overlay/pages/hydration-error-state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
isErrorMessageWithComponentStackDiff as isReact19HydrationWarning,
99
} from '../../react-19-hydration-error'
1010

11-
type HydrationErrorState = {
11+
export type HydrationErrorState = {
1212
// Hydration warning template format: <message> <serverContent> <clientContent>
1313
warning?: string
1414
reactOutputComponentDiff?: string

packages/next/src/client/components/react-dev-overlay/pages/pages-dev-overlay.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PagesDevOverlayErrorBoundary } from './pages-dev-overlay-error-boundary
22
import { usePagesDevOverlay } from './hooks'
33
import { FontStyles } from '../font/font-styles'
44
import { DevOverlay } from '../ui/dev-overlay'
5+
import { getSquashedHydrationErrorDetails } from './hydration-error-state'
56

67
export type ErrorType = 'runtime' | 'build'
78

@@ -22,7 +23,11 @@ export function PagesDevOverlay({ children }: PagesDevOverlayProps) {
2223

2324
{/* Fonts can only be loaded outside the Shadow DOM. */}
2425
<FontStyles />
25-
<DevOverlay state={state} dispatch={dispatch} />
26+
<DevOverlay
27+
state={state}
28+
dispatch={dispatch}
29+
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
30+
/>
2631
</>
2732
)
2833
}

packages/next/src/client/components/react-dev-overlay/ui/components/errors/error-overlay/error-overlay.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BuildError } from '../../../container/build-error'
99
import { Errors } from '../../../container/errors'
1010
import { useDelayedRender } from '../../../hooks/use-delayed-render'
1111
import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type'
12+
import type { HydrationErrorState } from '../../../../pages/hydration-error-state'
1213

1314
const transitionDurationMs = 200
1415

@@ -23,11 +24,13 @@ export interface ErrorBaseProps {
2324
export function ErrorOverlay({
2425
state,
2526
dispatch,
27+
getSquashedHydrationErrorDetails,
2628
runtimeErrors,
2729
errorCount,
2830
}: {
2931
state: OverlayState
3032
dispatch: OverlayDispatch
33+
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
3134
runtimeErrors: ReadyRuntimeError[]
3235
errorCount: number
3336
}) {
@@ -74,6 +77,7 @@ export function ErrorOverlay({
7477
<Errors
7578
{...commonProps}
7679
debugInfo={state.debugInfo}
80+
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
7781
runtimeErrors={runtimeErrors}
7882
onClose={() => {
7983
dispatch({ type: ACTION_ERROR_OVERLAY_CLOSE })

packages/next/src/client/components/react-dev-overlay/ui/container/errors.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717
} from '../../../react-19-hydration-error'
1818
import type { ReadyRuntimeError } from '../../utils/get-error-by-type'
1919
import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay'
20-
import { getSquashedHydrationErrorDetails } from '../../pages/hydration-error-state'
20+
import type { HydrationErrorState } from '../../pages/hydration-error-state'
2121

2222
export interface ErrorsProps extends ErrorBaseProps {
23+
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
2324
runtimeErrors: ReadyRuntimeError[]
2425
debugInfo: DebugInfo
2526
onClose: () => void
@@ -72,7 +73,10 @@ const noErrorDetails = {
7273
notes: null,
7374
reactOutputComponentDiff: null,
7475
}
75-
function useErrorDetails(error: Error | undefined): {
76+
function useErrorDetails(
77+
error: Error | undefined,
78+
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
79+
): {
7680
hydrationWarning: string | null
7781
notes: string | null
7882
reactOutputComponentDiff: string | null
@@ -106,10 +110,11 @@ function useErrorDetails(error: Error | undefined): {
106110
notes,
107111
reactOutputComponentDiff: diff,
108112
}
109-
}, [error])
113+
}, [error, getSquashedHydrationErrorDetails])
110114
}
111115

112116
export function Errors({
117+
getSquashedHydrationErrorDetails,
113118
runtimeErrors,
114119
debugInfo,
115120
onClose,
@@ -127,7 +132,10 @@ export function Errors({
127132
() => runtimeErrors[activeIdx] ?? null,
128133
[activeIdx, runtimeErrors]
129134
)
130-
const errorDetails = useErrorDetails(activeError?.error)
135+
const errorDetails = useErrorDetails(
136+
activeError?.error,
137+
getSquashedHydrationErrorDetails
138+
)
131139

132140
if (isLoading) {
133141
// TODO: better loading state

packages/next/src/client/components/react-dev-overlay/ui/dev-overlay.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import { DevToolsIndicator } from './components/errors/dev-tools-indicator/dev-t
1010
import { RenderError } from './container/runtime-error/render-error'
1111
import { DarkTheme } from './styles/dark-theme'
1212
import { useDevToolsScale } from './components/errors/dev-tools-indicator/dev-tools-info/preferences'
13+
import type { HydrationErrorState } from '../pages/hydration-error-state'
1314

1415
export function DevOverlay({
1516
state,
1617
dispatch,
18+
getSquashedHydrationErrorDetails,
1719
}: {
1820
state: OverlayState
1921
dispatch: OverlayDispatch
22+
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
2023
}) {
2124
const [scale, setScale] = useDevToolsScale()
2225
return (
@@ -46,6 +49,9 @@ export function DevOverlay({
4649
<ErrorOverlay
4750
state={state}
4851
dispatch={dispatch}
52+
getSquashedHydrationErrorDetails={
53+
getSquashedHydrationErrorDetails
54+
}
4955
runtimeErrors={runtimeErrors}
5056
errorCount={totalErrorCount}
5157
/>

0 commit comments

Comments
 (0)