silverwolf-x/project / packages /next /src /next-devtools /dev-overlay /hooks /use-active-runtime-error.ts
silverwolf-x's picture
download
raw
1.47 kB
import type { ReadyRuntimeError } from '../utils/get-error-by-type'
import type { HydrationErrorState } from '../../shared/hydration-error'
import { useMemo, useState } from 'react'
import { getErrorTypeLabel, useErrorDetails } from '../container/errors'
import { extractNextErrorCode } from '../../../lib/error-telemetry-utils'
export function useActiveRuntimeError({
runtimeErrors,
getSquashedHydrationErrorDetails,
}: {
runtimeErrors: ReadyRuntimeError[]
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
}) {
const [activeIdx, setActiveIndex] = useState<number>(0)
const isLoading = useMemo<boolean>(() => {
return runtimeErrors.length === 0
}, [runtimeErrors.length])
const activeError = useMemo<ReadyRuntimeError | null>(
() => runtimeErrors[activeIdx] ?? null,
[activeIdx, runtimeErrors]
)
const errorDetails = useErrorDetails(
activeError?.error,
getSquashedHydrationErrorDetails
)
if (isLoading || !activeError) {
return {
isLoading,
activeIdx,
setActiveIndex,
activeError: null,
errorDetails: null,
errorCode: null,
errorType: null,
}
}
const error = activeError.error
const errorCode = extractNextErrorCode(error)
const errorType = getErrorTypeLabel(error, activeError.type, errorDetails)
return {
isLoading,
activeIdx,
setActiveIndex,
activeError,
errorDetails,
errorCode,
errorType,
}
}

Xet Storage Details

Size:
1.47 kB
·
Xet hash:
c0ffaed273297d7190d2a504e6e05837a6edab78653daf88cd12dd26a968b5b3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.