Skip to content

Commit a5ba001

Browse files
committed
fixup! [dev-overlay] Remove unused code
1 parent a751865 commit a5ba001

30 files changed

+120
-177
lines changed

packages/next/src/client/app-index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// imports polyfill from `@next/polyfill-module` after build.
22
import '../build/polyfills/polyfill-module'
33

4-
import './components/globals/patch-console'
5-
import './components/globals/handle-global-errors'
4+
import './components/react-dev-overlay/app/app-dev-overlay-setup'
65

76
import ReactDOMClient from 'react-dom/client'
87
import React, { use } from 'react'

packages/next/src/client/app-next-dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { appBootstrap } from './app-bootstrap'
77
import {
88
getComponentStack,
99
getOwnerStack,
10-
} from './components/errors/stitched-error'
10+
} from './components/react-dev-overlay/app/errors/stitched-error'
1111
import { isRecoverableError } from './react-client-callbacks/on-recoverable-error'
1212

1313
// eslint-disable-next-line @next/internal/typechecked-require

packages/next/src/client/app-next-turbopack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { appBootstrap } from './app-bootstrap'
22
import {
33
getComponentStack,
44
getOwnerStack,
5-
} from './components/errors/stitched-error'
5+
} from './components/react-dev-overlay/app/errors/stitched-error'
66
import { isRecoverableError } from './react-client-callbacks/on-recoverable-error'
77

88
window.next.version += '-turbo'

packages/next/src/client/components/globals/handle-global-errors.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/next/src/client/components/globals/patch-console.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PureComponent } from 'react'
22
import { dispatcher } from 'next/dist/compiled/next-devtools'
3-
import { RuntimeErrorHandler } from '../../errors/runtime-error-handler'
3+
import { RuntimeErrorHandler } from '../runtime-error-handler'
44
import { ErrorBoundary } from '../../error-boundary'
55
import DefaultGlobalError, {
66
type GlobalErrorComponent,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { patchConsoleError } from './errors/intercept-console-error'
2+
import { handleGlobalErrors } from './errors/use-error-handler'
3+
4+
handleGlobalErrors()
5+
patchConsoleError()

packages/next/src/client/components/globals/intercept-console-error.ts renamed to packages/next/src/client/components/react-dev-overlay/app/errors/intercept-console-error.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import isError from '../../../lib/is-error'
2-
import { isNextRouterError } from '../is-next-router-error'
3-
import { handleConsoleError } from '../errors/use-error-handler'
4-
import { parseConsoleArgs } from '../../lib/console'
1+
import isError from '../../../../../lib/is-error'
2+
import { isNextRouterError } from '../../../is-next-router-error'
3+
import { handleConsoleError } from './use-error-handler'
4+
import { parseConsoleArgs } from '../../../../lib/console'
55

66
export const originConsoleError = globalThis.console.error
77

packages/next/src/client/components/react-dev-overlay/app/replay-ssr-only-errors.tsx renamed to packages/next/src/client/components/react-dev-overlay/app/errors/replay-ssr-only-errors.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react'
2-
import { handleClientError } from '../../errors/use-error-handler'
3-
import { isNextRouterError } from '../../is-next-router-error'
4-
import { MISSING_ROOT_TAGS_ERROR } from '../../../../shared/lib/errors/constants'
2+
import { handleClientError } from './use-error-handler'
3+
import { isNextRouterError } from '../../../is-next-router-error'
4+
import { MISSING_ROOT_TAGS_ERROR } from '../../../../../shared/lib/errors/constants'
55

66
function readSsrError(): (Error & { digest?: string }) | null {
77
if (typeof document === 'undefined') {

packages/next/src/client/components/errors/stitched-error.ts renamed to packages/next/src/client/components/react-dev-overlay/app/errors/stitched-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import isError from '../../../lib/is-error'
2+
import isError from '../../../../../lib/is-error'
33

44
const ownerStacks = new WeakMap<Error, string | null>()
55
const componentStacks = new WeakMap<Error, string>()

packages/next/src/client/components/errors/use-error-handler.ts renamed to packages/next/src/client/components/react-dev-overlay/app/errors/use-error-handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useEffect } from 'react'
2-
import { isNextRouterError } from '../is-next-router-error'
3-
import { formatConsoleArgs, parseConsoleArgs } from '../../lib/console'
4-
import isError from '../../../lib/is-error'
2+
import { isNextRouterError } from '../../../is-next-router-error'
3+
import { formatConsoleArgs, parseConsoleArgs } from '../../../../lib/console'
4+
import isError from '../../../../../lib/is-error'
55
import { createConsoleError } from './console-error'
6-
import { coerceError, setOwnerStackIfAvailable } from '../errors/stitched-error'
6+
import { coerceError, setOwnerStackIfAvailable } from './stitched-error'
77

88
const queueMicroTask =
99
globalThis.queueMicrotask || ((cb: () => void) => Promise.resolve().then(cb))

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/next/src/client/components/react-dev-overlay/pages/client.ts renamed to packages/next/src/client/components/react-dev-overlay/pages/pages-dev-overlay-setup.tsx

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,53 @@
1+
import React from 'react'
2+
import { renderPagesDevOverlay } from 'next/dist/compiled/next-devtools'
13
import { dispatcher } from 'next/dist/compiled/next-devtools'
24
import {
35
attachHydrationErrorState,
46
storeHydrationErrorStateFromConsoleArgs,
57
} from './hydration-error-state'
6-
import type { VersionInfo } from '../../../../server/dev/parse-version-info'
7-
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
8+
import { Router } from '../../../router'
9+
import { getComponentStack, getOwnerStack } from '../app/errors/stitched-error'
10+
import { isRecoverableError } from '../../../react-client-callbacks/on-recoverable-error'
11+
import { getSquashedHydrationErrorDetails } from './hydration-error-state'
12+
import { PagesDevOverlayErrorBoundary } from './pages-dev-overlay-error-boundary'
13+
14+
const usePagesDevOverlayBridge = () => {
15+
React.useInsertionEffect(() => {
16+
// NDT uses a different React instance so it's not technically a state update
17+
// scheduled from useInsertionEffect.
18+
renderPagesDevOverlay(
19+
getComponentStack,
20+
getOwnerStack,
21+
getSquashedHydrationErrorDetails,
22+
isRecoverableError
23+
)
24+
}, [])
25+
26+
React.useEffect(() => {
27+
const { handleStaticIndicator } =
28+
require('../../../dev/hot-reloader/pages/hot-reloader-pages') as typeof import('../../../dev/hot-reloader/pages/hot-reloader-pages')
29+
30+
Router.events.on('routeChangeComplete', handleStaticIndicator)
31+
32+
return function () {
33+
Router.events.off('routeChangeComplete', handleStaticIndicator)
34+
}
35+
}, [])
36+
}
37+
38+
export type PagesDevOverlayBridgeType = typeof PagesDevOverlayBridge
39+
40+
interface PagesDevOverlayBridgeProps {
41+
children?: React.ReactNode
42+
}
43+
44+
export function PagesDevOverlayBridge({
45+
children,
46+
}: PagesDevOverlayBridgeProps) {
47+
usePagesDevOverlayBridge()
48+
49+
return <PagesDevOverlayErrorBoundary>{children}</PagesDevOverlayErrorBoundary>
50+
}
851

952
let isRegistered = false
1053

@@ -69,42 +112,3 @@ export function register() {
69112
window.addEventListener('unhandledrejection', onUnhandledRejection)
70113
window.console.error = nextJsHandleConsoleError
71114
}
72-
73-
export function onBuildOk() {
74-
dispatcher.onBuildOk()
75-
}
76-
77-
export function onBuildError(message: string) {
78-
dispatcher.onBuildError(message)
79-
}
80-
81-
export function onRefresh() {
82-
dispatcher.onRefresh()
83-
}
84-
85-
export function onBeforeRefresh() {
86-
dispatcher.onBeforeRefresh()
87-
}
88-
89-
export function onVersionInfo(versionInfo: VersionInfo) {
90-
dispatcher.onVersionInfo(versionInfo)
91-
}
92-
93-
export function onStaticIndicator(isStatic: boolean) {
94-
dispatcher.onStaticIndicator(isStatic)
95-
}
96-
97-
export function onDevIndicator(devIndicatorsState: DevIndicatorServerState) {
98-
dispatcher.onDevIndicator(devIndicatorsState)
99-
}
100-
101-
export function buildingIndicatorShow() {
102-
dispatcher.buildingIndicatorShow()
103-
}
104-
105-
export function buildingIndicatorHide() {
106-
dispatcher.buildingIndicatorHide()
107-
}
108-
109-
export { getErrorByType } from '../utils/get-error-by-type'
110-
export { getServerError } from '../utils/node-stack-frames'

packages/next/src/client/components/react-dev-overlay/server/middleware-webpack.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
type OriginalStackFramesResponse,
1717
} from './shared'
1818
import { middlewareResponse } from './middleware-response'
19-
export { getServerError } from '../utils/node-stack-frames'
2019
export { parseStack } from '../utils/parse-stack'
2120
export { getSourceMapFromFile }
2221

packages/next/src/client/components/react-dev-overlay/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { parseComponentStack } from './utils/parse-component-stack'
66
import type { DebugInfo } from './types'
77
import type { DevIndicatorServerState } from '../../../server/dev/dev-indicator-server-state'
88
import { parseStack } from './utils/parse-stack'
9-
import { isConsoleError } from '../errors/console-error'
9+
import { isConsoleError } from './app/errors/console-error'
1010

1111
type FastRefreshState =
1212
/** No refresh in progress. */

packages/next/src/client/components/react-dev-overlay/utils/node-stack-frames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type ErrorSourceType,
66
} from '../../../../shared/lib/error-source'
77

8-
export function getFilesystemFrame(frame: StackFrame): StackFrame {
8+
function getFilesystemFrame(frame: StackFrame): StackFrame {
99
const f: StackFrame = { ...frame }
1010

1111
if (typeof f.file === 'string') {

packages/next/src/client/dev/hot-reloader/app/hot-reloader-app.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import { useEffect, startTransition, useRef } from 'react'
55
import stripAnsi from 'next/dist/compiled/strip-ansi'
66
import formatWebpackMessages from '../../../components/react-dev-overlay/utils/format-webpack-messages'
77
import { useRouter } from '../../../components/navigation'
8-
import { REACT_REFRESH_FULL_RELOAD } from '../shared'
9-
import { reportInvalidHmrMessage } from '../shared'
8+
import {
9+
REACT_REFRESH_FULL_RELOAD,
10+
REACT_REFRESH_FULL_RELOAD_FROM_ERROR,
11+
reportInvalidHmrMessage,
12+
} from '../shared'
1013
import { dispatcher } from 'next/dist/compiled/next-devtools'
11-
import { ReplaySsrOnlyErrors } from '../../../components/react-dev-overlay/app/replay-ssr-only-errors'
14+
import { ReplaySsrOnlyErrors } from '../../../components/react-dev-overlay/app/errors/replay-ssr-only-errors'
1215
import { AppDevOverlayErrorBoundary } from '../../../components/react-dev-overlay/app/app-dev-overlay-error-boundary'
13-
import { useErrorHandler } from '../../../components/errors/use-error-handler'
14-
import { RuntimeErrorHandler } from '../../../components/errors/runtime-error-handler'
16+
import { useErrorHandler } from '../../../components/react-dev-overlay/app/errors/use-error-handler'
17+
import { RuntimeErrorHandler } from '../../../components/react-dev-overlay/runtime-error-handler'
1518
import {
1619
useSendMessage,
1720
useTurbopack,
@@ -23,7 +26,6 @@ import type {
2326
HMR_ACTION_TYPES,
2427
TurbopackMsgToBrowser,
2528
} from '../../../../server/dev/hot-reloader-types'
26-
import { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from '../shared'
2729
import { useUntrackedPathname } from '../../../components/navigation-untracked'
2830
import type { GlobalErrorComponent } from '../../../components/global-error'
2931
import reportHmrLatency from '../../../components/react-dev-overlay/utils/report-hmr-latency'

0 commit comments

Comments
 (0)