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

[dev-overlay] Inject `getSquashedHydrationErrorDetails` implementation (#80046)

Same as with `get*Stack` implementation
parent 69765f4d
...@@ -72,6 +72,11 @@ function ReplaySsrOnlyErrors({ ...@@ -72,6 +72,11 @@ function ReplaySsrOnlyErrors({
return null return null
} }
function getSquashedHydrationErrorDetails() {
// We don't squash hydration errors in the App Router.
return null
}
export function AppDevOverlay({ export function AppDevOverlay({
state, state,
dispatch, dispatch,
...@@ -99,7 +104,11 @@ export function AppDevOverlay({ ...@@ -99,7 +104,11 @@ export function AppDevOverlay({
<> <>
{/* Fonts can only be loaded outside the Shadow DOM. */} {/* Fonts can only be loaded outside the Shadow DOM. */}
<FontStyles /> <FontStyles />
<DevOverlay state={state} dispatch={dispatch} /> <DevOverlay
state={state}
dispatch={dispatch}
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
/>
</> </>
</> </>
) )
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
isErrorMessageWithComponentStackDiff as isReact19HydrationWarning, isErrorMessageWithComponentStackDiff as isReact19HydrationWarning,
} from '../../react-19-hydration-error' } from '../../react-19-hydration-error'
type HydrationErrorState = { export type HydrationErrorState = {
// Hydration warning template format: <message> <serverContent> <clientContent> // Hydration warning template format: <message> <serverContent> <clientContent>
warning?: string warning?: string
reactOutputComponentDiff?: string reactOutputComponentDiff?: string
......
...@@ -2,6 +2,7 @@ import { PagesDevOverlayErrorBoundary } from './pages-dev-overlay-error-boundary ...@@ -2,6 +2,7 @@ import { PagesDevOverlayErrorBoundary } from './pages-dev-overlay-error-boundary
import { usePagesDevOverlay } from './hooks' import { usePagesDevOverlay } from './hooks'
import { FontStyles } from '../font/font-styles' import { FontStyles } from '../font/font-styles'
import { DevOverlay } from '../ui/dev-overlay' import { DevOverlay } from '../ui/dev-overlay'
import { getSquashedHydrationErrorDetails } from './hydration-error-state'
export type ErrorType = 'runtime' | 'build' export type ErrorType = 'runtime' | 'build'
...@@ -22,7 +23,11 @@ export function PagesDevOverlay({ children }: PagesDevOverlayProps) { ...@@ -22,7 +23,11 @@ export function PagesDevOverlay({ children }: PagesDevOverlayProps) {
{/* Fonts can only be loaded outside the Shadow DOM. */} {/* Fonts can only be loaded outside the Shadow DOM. */}
<FontStyles /> <FontStyles />
<DevOverlay state={state} dispatch={dispatch} /> <DevOverlay
state={state}
dispatch={dispatch}
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
/>
</> </>
) )
} }
...@@ -9,6 +9,7 @@ import { BuildError } from '../../../container/build-error' ...@@ -9,6 +9,7 @@ import { BuildError } from '../../../container/build-error'
import { Errors } from '../../../container/errors' import { Errors } from '../../../container/errors'
import { useDelayedRender } from '../../../hooks/use-delayed-render' import { useDelayedRender } from '../../../hooks/use-delayed-render'
import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type'
import type { HydrationErrorState } from '../../../../pages/hydration-error-state'
const transitionDurationMs = 200 const transitionDurationMs = 200
...@@ -23,11 +24,13 @@ export interface ErrorBaseProps { ...@@ -23,11 +24,13 @@ export interface ErrorBaseProps {
export function ErrorOverlay({ export function ErrorOverlay({
state, state,
dispatch, dispatch,
getSquashedHydrationErrorDetails,
runtimeErrors, runtimeErrors,
errorCount, errorCount,
}: { }: {
state: OverlayState state: OverlayState
dispatch: OverlayDispatch dispatch: OverlayDispatch
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
errorCount: number errorCount: number
}) { }) {
...@@ -74,6 +77,7 @@ export function ErrorOverlay({ ...@@ -74,6 +77,7 @@ export function ErrorOverlay({
<Errors <Errors
{...commonProps} {...commonProps}
debugInfo={state.debugInfo} debugInfo={state.debugInfo}
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
runtimeErrors={runtimeErrors} runtimeErrors={runtimeErrors}
onClose={() => { onClose={() => {
dispatch({ type: ACTION_ERROR_OVERLAY_CLOSE }) dispatch({ type: ACTION_ERROR_OVERLAY_CLOSE })
......
...@@ -17,9 +17,10 @@ import { ...@@ -17,9 +17,10 @@ import {
} from '../../../react-19-hydration-error' } from '../../../react-19-hydration-error'
import type { ReadyRuntimeError } from '../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../utils/get-error-by-type'
import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay' import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay'
import { getSquashedHydrationErrorDetails } from '../../pages/hydration-error-state' import type { HydrationErrorState } from '../../pages/hydration-error-state'
export interface ErrorsProps extends ErrorBaseProps { export interface ErrorsProps extends ErrorBaseProps {
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
debugInfo: DebugInfo debugInfo: DebugInfo
onClose: () => void onClose: () => void
...@@ -72,7 +73,10 @@ const noErrorDetails = { ...@@ -72,7 +73,10 @@ const noErrorDetails = {
notes: null, notes: null,
reactOutputComponentDiff: null, reactOutputComponentDiff: null,
} }
function useErrorDetails(error: Error | undefined): { function useErrorDetails(
error: Error | undefined,
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
): {
hydrationWarning: string | null hydrationWarning: string | null
notes: string | null notes: string | null
reactOutputComponentDiff: string | null reactOutputComponentDiff: string | null
...@@ -106,10 +110,11 @@ function useErrorDetails(error: Error | undefined): { ...@@ -106,10 +110,11 @@ function useErrorDetails(error: Error | undefined): {
notes, notes,
reactOutputComponentDiff: diff, reactOutputComponentDiff: diff,
} }
}, [error]) }, [error, getSquashedHydrationErrorDetails])
} }
export function Errors({ export function Errors({
getSquashedHydrationErrorDetails,
runtimeErrors, runtimeErrors,
debugInfo, debugInfo,
onClose, onClose,
...@@ -127,7 +132,10 @@ export function Errors({ ...@@ -127,7 +132,10 @@ export function Errors({
() => runtimeErrors[activeIdx] ?? null, () => runtimeErrors[activeIdx] ?? null,
[activeIdx, runtimeErrors] [activeIdx, runtimeErrors]
) )
const errorDetails = useErrorDetails(activeError?.error) const errorDetails = useErrorDetails(
activeError?.error,
getSquashedHydrationErrorDetails
)
if (isLoading) { if (isLoading) {
// TODO: better loading state // TODO: better loading state
......
...@@ -102,6 +102,10 @@ function useOverlayReducer() { ...@@ -102,6 +102,10 @@ function useOverlayReducer() {
}, initialState) }, initialState)
} }
function getNoSquashedHydrationErrorDetails() {
return null
}
export const Default: Story = { export const Default: Story = {
render: function DevOverlayStory() { render: function DevOverlayStory() {
const [state, dispatch] = useOverlayReducer() const [state, dispatch] = useOverlayReducer()
...@@ -115,7 +119,14 @@ export const Default: Story = { ...@@ -115,7 +119,14 @@ export const Default: Story = {
objectFit: 'contain', objectFit: 'contain',
}} }}
/> />
<DevOverlay state={state} dispatch={dispatch} /> <DevOverlay
state={state}
dispatch={dispatch}
getSquashedHydrationErrorDetails={
// Testing like App Router where we no longer quash hydration errors
getNoSquashedHydrationErrorDetails
}
/>
</> </>
) )
}, },
......
...@@ -10,13 +10,16 @@ import { DevToolsIndicator } from './components/errors/dev-tools-indicator/dev-t ...@@ -10,13 +10,16 @@ import { DevToolsIndicator } from './components/errors/dev-tools-indicator/dev-t
import { RenderError } from './container/runtime-error/render-error' import { RenderError } from './container/runtime-error/render-error'
import { DarkTheme } from './styles/dark-theme' import { DarkTheme } from './styles/dark-theme'
import { useDevToolsScale } from './components/errors/dev-tools-indicator/dev-tools-info/preferences' import { useDevToolsScale } from './components/errors/dev-tools-indicator/dev-tools-info/preferences'
import type { HydrationErrorState } from '../pages/hydration-error-state'
export function DevOverlay({ export function DevOverlay({
state, state,
dispatch, dispatch,
getSquashedHydrationErrorDetails,
}: { }: {
state: OverlayState state: OverlayState
dispatch: OverlayDispatch dispatch: OverlayDispatch
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
}) { }) {
const [scale, setScale] = useDevToolsScale() const [scale, setScale] = useDevToolsScale()
return ( return (
...@@ -46,6 +49,9 @@ export function DevOverlay({ ...@@ -46,6 +49,9 @@ export function DevOverlay({
<ErrorOverlay <ErrorOverlay
state={state} state={state}
dispatch={dispatch} dispatch={dispatch}
getSquashedHydrationErrorDetails={
getSquashedHydrationErrorDetails
}
runtimeErrors={runtimeErrors} runtimeErrors={runtimeErrors}
errorCount={totalErrorCount} errorCount={totalErrorCount}
/> />
......
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