Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up react-dev-overlay before fork #74016

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/client/app-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function hydrate() {
shouldRenderRootLevelErrorOverlay()
) {
const { createRootLevelDevOverlayElement } =
require('./components/react-dev-overlay/client-entry') as typeof import('./components/react-dev-overlay/client-entry')
require('./components/react-dev-overlay/app/client-entry') as typeof import('./components/react-dev-overlay/app/client-entry')

// Note this won't cause hydration mismatch because we are doing CSR w/o hydration
element = createRootLevelDevOverlayElement(element)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import ReactDevOverlay from './app/ReactDevOverlay'
import { getSocketUrl } from './internal/helpers/get-socket-url'
import { INITIAL_OVERLAY_STATE } from './shared'
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../server/dev/hot-reloader-types'
import ReactDevOverlay from './ReactDevOverlay'
import { getSocketUrl } from '../internal/helpers/get-socket-url'
import { INITIAL_OVERLAY_STATE } from '../shared'
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../../server/dev/hot-reloader-types'

// if an error is thrown while rendering an RSC stream, this will catch it in dev
// and show the error overlay
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import * as React from 'react'

import * as Bus from './bus'
import { ShadowPortal } from '../internal/components/ShadowPortal'
import { BuildError } from '../internal/container/BuildError'
import { Errors } from '../internal/container/Errors'
import { ErrorBoundary } from './ErrorBoundary'
import { Base } from '../internal/styles/Base'
import { ComponentStyles } from '../internal/styles/ComponentStyles'
import { CssReset } from '../internal/styles/CssReset'
import { useErrorOverlayReducer } from '../shared'
import { usePagesReactDevOverlay } from './hooks'

type ErrorType = 'runtime' | 'build'

const shouldPreventDisplay = (
errorType?: ErrorType | null,
preventType?: ErrorType[] | null
) => {
if (!preventType || !errorType) {
return false
}
return preventType.includes(errorType)
}
export type ErrorType = 'runtime' | 'build'

interface ReactDevOverlayProps {
children?: React.ReactNode
Expand All @@ -33,32 +22,14 @@ export default function ReactDevOverlay({
preventDisplay,
globalOverlay,
}: ReactDevOverlayProps) {
const [state, dispatch] = useErrorOverlayReducer()

React.useEffect(() => {
Bus.on(dispatch)
return function () {
Bus.off(dispatch)
}
}, [dispatch])

const onComponentError = React.useCallback(
(_error: Error, _componentStack: string | null) => {
// TODO: special handling
},
[]
)

const hasBuildError = state.buildError != null
const hasRuntimeErrors = Boolean(state.errors.length)
const errorType = hasBuildError
? 'build'
: hasRuntimeErrors
? 'runtime'
: null
const isMounted = errorType !== null

const displayPrevented = shouldPreventDisplay(errorType, preventDisplay)
const {
isMounted,
displayPrevented,
hasBuildError,
hasRuntimeErrors,
state,
onComponentError,
} = usePagesReactDevOverlay(preventDisplay)

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { ErrorType } from './ReactDevOverlay'
import React from 'react'
import * as Bus from './bus'
import { useErrorOverlayReducer } from '../shared'

const shouldPreventDisplay = (
errorType?: ErrorType | null,
preventType?: ErrorType[] | null
) => {
if (!preventType || !errorType) {
return false
}
return preventType.includes(errorType)
}

export const usePagesReactDevOverlay = (
preventDisplay: ErrorType[] | undefined
) => {
const [state, dispatch] = useErrorOverlayReducer()

React.useEffect(() => {
Bus.on(dispatch)
return function () {
Bus.off(dispatch)
}
}, [dispatch])

const onComponentError = React.useCallback(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this later since this not really being used

(_error: Error, _componentStack: string | null) => {
// TODO: special handling
},
[]
)

const hasBuildError = state.buildError != null
const hasRuntimeErrors = Boolean(state.errors.length)
const errorType = hasBuildError
? 'build'
: hasRuntimeErrors
? 'runtime'
: null
const isMounted = errorType !== null

const displayPrevented = shouldPreventDisplay(errorType, preventDisplay)
return {
isMounted,
displayPrevented,
hasBuildError,
hasRuntimeErrors,
state,
onComponentError,
}
}
Loading