Unverified Commit 379ba00c authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Remove unused devtools code handling React without `use` (#89793)

parent ae64f6cf
...@@ -68,20 +68,9 @@ const RenderRuntimeError = ({ children, state, isAppDir }: Props) => { ...@@ -68,20 +68,9 @@ const RenderRuntimeError = ({ children, state, isAppDir }: Props) => {
return return
} }
let mounted = true const resolved = getErrorByType(nextError, isAppDir)
// eslint-disable-next-line react-hooks/set-state-in-effect -- TODO: fetch-while-rendering
getErrorByType(nextError, isAppDir).then((resolved) => { setLookups((m) => ({ ...m, [resolved.id]: resolved }))
if (mounted) {
// We don't care if the desired error changed while we were resolving,
// thus we're not tracking it using a ref. Once the work has been done,
// we'll store it.
setLookups((m) => ({ ...m, [resolved.id]: resolved }))
}
})
return () => {
mounted = false
}
}, [nextError, isAppDir]) }, [nextError, isAppDir])
const totalErrorCount = errors.length const totalErrorCount = errors.length
......
...@@ -8,9 +8,7 @@ export type ReadyRuntimeError = { ...@@ -8,9 +8,7 @@ export type ReadyRuntimeError = {
id: number id: number
runtime: true runtime: true
error: Error & { environmentName?: string } error: Error & { environmentName?: string }
frames: frames: () => Promise<readonly OriginalStackFrame[]>
| readonly OriginalStackFrame[]
| (() => Promise<readonly OriginalStackFrame[]>)
type: 'runtime' | 'console' | 'recoverable' type: 'runtime' | 'console' | 'recoverable'
} }
...@@ -19,63 +17,29 @@ export const useFrames = ( ...@@ -19,63 +17,29 @@ export const useFrames = (
): readonly OriginalStackFrame[] => { ): readonly OriginalStackFrame[] => {
if (!error) return [] if (!error) return []
if ('use' in React) { const frames = error.frames
const frames = error.frames return React.use(frames())
if (typeof frames !== 'function') {
throw new Error(
'Invariant: frames must be a function when the React version has React.use. This is a bug in Next.js.'
)
}
return React.use((frames as () => Promise<readonly OriginalStackFrame[]>)())
} else {
if (!Array.isArray(error.frames)) {
throw new Error(
'Invariant: frames must be an array when the React version does not have React.use. This is a bug in Next.js.'
)
}
return error.frames
}
} }
export async function getErrorByType( export function getErrorByType(
event: SupportedErrorEvent, event: SupportedErrorEvent,
isAppDir: boolean isAppDir: boolean
): Promise<ReadyRuntimeError> { ): ReadyRuntimeError {
const baseError = { const readyRuntimeError: ReadyRuntimeError = {
id: event.id, id: event.id,
runtime: true, runtime: true,
error: event.error, error: event.error,
type: event.type, type: event.type,
} as const // createMemoizedPromise dedups calls to getOriginalStackFrames
frames: createMemoizedPromise(async () => {
if ('use' in React) { return await getOriginalStackFrames(
const readyRuntimeError: ReadyRuntimeError = {
...baseError,
// createMemoizedPromise dedups calls to getOriginalStackFrames
frames: createMemoizedPromise(async () => {
return await getOriginalStackFrames(
event.frames,
getErrorSource(event.error),
isAppDir
)
}),
}
return readyRuntimeError
} else {
const readyRuntimeError: ReadyRuntimeError = {
...baseError,
// createMemoizedPromise dedups calls to getOriginalStackFrames
frames: await getOriginalStackFrames(
event.frames, event.frames,
getErrorSource(event.error), getErrorSource(event.error),
isAppDir isAppDir
), )
} }),
return readyRuntimeError
} }
return readyRuntimeError
} }
function createMemoizedPromise<T>( function createMemoizedPromise<T>(
......
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