Skip to content

Commit 62818e2

Browse files
committed
use use-runtime-error hook
1 parent 8ded927 commit 62818e2

File tree

1 file changed

+28
-33
lines changed
  • packages/next/src/next-devtools/dev-overlay/components/devtools-panel/devtools-panel-tab/issues-tab

1 file changed

+28
-33
lines changed

packages/next/src/next-devtools/dev-overlay/components/devtools-panel/devtools-panel-tab/issues-tab/issues-tab.tsx

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { Suspense, useMemo, useState } from 'react'
1+
import { Suspense, useMemo } from 'react'
22
import {
33
GenericErrorDescription,
4-
getErrorTypeLabel,
54
HydrationErrorDescription,
6-
useErrorDetails,
75
} from '../../../../container/errors'
86
import { EnvironmentNameLabel } from '../../../errors/environment-name-label/environment-name-label'
97
import { ErrorMessage } from '../../../errors/error-message/error-message'
@@ -15,7 +13,6 @@ import {
1513
} from '../../../../utils/get-error-by-type'
1614
import type { HydrationErrorState } from '../../../../../shared/hydration-error'
1715
import type { OverlayState } from '../../../../shared'
18-
import { extractNextErrorCode } from '../../../../../../lib/error-telemetry-utils'
1916
import { css } from '../../../../utils/css'
2017
import { getFrameSource } from '../../../../../shared/stack-frame'
2118
import { Terminal } from '../../../terminal'
@@ -24,6 +21,7 @@ import { NEXTJS_HYDRATION_ERROR_LINK } from '../../../../../shared/react-19-hydr
2421
import { PseudoHtmlDiff } from '../../../../container/runtime-error/component-stack-pseudo-html'
2522
import { CodeFrame } from '../../../code-frame/code-frame'
2623
import { CallStack } from '../../../call-stack/call-stack'
24+
import { useRuntimeError } from '../../../../hooks/use-runtime-error'
2725

2826
export function IssuesTab({
2927
state,
@@ -34,39 +32,31 @@ export function IssuesTab({
3432
runtimeErrors: ReadyRuntimeError[]
3533
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
3634
}) {
37-
const [activeIdx, setActiveIndex] = useState<number>(0)
38-
const activeError = useMemo<ReadyRuntimeError | null>(
39-
() =>
40-
// TODO: correct fallback
41-
runtimeErrors[activeIdx] ?? {
42-
error: new Error('No error'),
43-
type: 'runtime',
44-
},
45-
[activeIdx, runtimeErrors]
46-
)
35+
const {
36+
isLoading,
37+
errorCode,
38+
errorType,
39+
notes,
40+
hydrationWarning,
41+
activeIdx,
42+
errorDetails,
43+
activeError,
44+
setActiveIndex,
45+
} = useRuntimeError({ runtimeErrors, getSquashedHydrationErrorDetails })
46+
47+
if (isLoading) {
48+
// TODO: better loading state
49+
return null
50+
}
4751

4852
if (!activeError) {
4953
return null
5054
}
5155

52-
// eslint-disable-next-line react-hooks/rules-of-hooks
53-
const errorDetails = useErrorDetails(
54-
activeError?.error,
55-
getSquashedHydrationErrorDetails
56-
)
57-
58-
const error = activeError?.error
59-
60-
const errorCode = extractNextErrorCode(error)
61-
const errorType = getErrorTypeLabel(error, activeError.type)
62-
// TOOD: May be better to always treat everything past the first blank line as notes
63-
// We're currently only special casing hydration error messages.
64-
const notes = errorDetails.notes
65-
const hydrationWarning = errorDetails.hydrationWarning
6656
const errorMessage = hydrationWarning ? (
6757
<HydrationErrorDescription message={hydrationWarning} />
6858
) : (
69-
<GenericErrorDescription error={error} />
59+
<GenericErrorDescription error={activeError.error} />
7060
)
7161

7262
return (
@@ -96,11 +86,16 @@ export function IssuesTab({
9686
>
9787
<span data-nextjs-error-label-group>
9888
<ErrorTypeLabel errorType={errorType} />
99-
{error.environmentName && (
100-
<EnvironmentNameLabel environmentName={error.environmentName} />
89+
{activeError.error.environmentName && (
90+
<EnvironmentNameLabel
91+
environmentName={activeError.error.environmentName}
92+
/>
10193
)}
10294
</span>
103-
<ErrorOverlayToolbar error={error} debugInfo={state.debugInfo} />
95+
<ErrorOverlayToolbar
96+
error={activeError.error}
97+
debugInfo={state.debugInfo}
98+
/>
10499
</div>
105100
<ErrorMessage errorMessage={errorMessage} />
106101
</div>
@@ -218,7 +213,7 @@ function Foo({
218213
setActiveIndex,
219214
}: {
220215
runtimeError: ReadyRuntimeError
221-
errorType: string
216+
errorType: string | null
222217
idx: number
223218
activeIdx: number
224219
setActiveIndex: (idx: number) => void

0 commit comments

Comments
 (0)