Unverified Commit 62bc131f authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[devtools] Make state read-only in types (#82396)

parent 373f3e1d
...@@ -10,7 +10,7 @@ export function CallStack({ ...@@ -10,7 +10,7 @@ export function CallStack({
ignoredFramesTally, ignoredFramesTally,
onToggleIgnoreList, onToggleIgnoreList,
}: { }: {
frames: OriginalStackFrame[] frames: readonly OriginalStackFrame[]
isIgnoreListOpen: boolean isIgnoreListOpen: boolean
ignoredFramesTally: number ignoredFramesTally: number
onToggleIgnoreList: () => void onToggleIgnoreList: () => void
......
...@@ -3,7 +3,7 @@ import { useMemo, useState, useRef } from 'react' ...@@ -3,7 +3,7 @@ import { useMemo, useState, useRef } from 'react'
import { CallStack } from '../../call-stack/call-stack' import { CallStack } from '../../call-stack/call-stack'
interface CallStackProps { interface CallStackProps {
frames: OriginalStackFrame[] frames: readonly OriginalStackFrame[]
dialogResizerRef: React.RefObject<HTMLDivElement | null> dialogResizerRef: React.RefObject<HTMLDivElement | null>
} }
......
...@@ -21,6 +21,7 @@ export const Default: Story = { ...@@ -21,6 +21,7 @@ export const Default: Story = {
runtime: true, runtime: true,
error: new Error('First error message'), error: new Error('First error message'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -28,6 +29,7 @@ export const Default: Story = { ...@@ -28,6 +29,7 @@ export const Default: Story = {
runtime: true, runtime: true,
error: new Error('Second error message'), error: new Error('Second error message'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -35,6 +37,7 @@ export const Default: Story = { ...@@ -35,6 +37,7 @@ export const Default: Story = {
runtime: true, runtime: true,
error: new Error('Third error message'), error: new Error('Third error message'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
], ],
......
...@@ -22,6 +22,7 @@ const mockErrors: ReadyRuntimeError[] = [ ...@@ -22,6 +22,7 @@ const mockErrors: ReadyRuntimeError[] = [
runtime: true as const, runtime: true as const,
error: new Error('First error'), error: new Error('First error'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -29,6 +30,7 @@ const mockErrors: ReadyRuntimeError[] = [ ...@@ -29,6 +30,7 @@ const mockErrors: ReadyRuntimeError[] = [
runtime: true as const, runtime: true as const,
error: new Error('Second error'), error: new Error('Second error'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -36,6 +38,7 @@ const mockErrors: ReadyRuntimeError[] = [ ...@@ -36,6 +38,7 @@ const mockErrors: ReadyRuntimeError[] = [
runtime: true as const, runtime: true as const,
error: new Error('Third error'), error: new Error('Third error'),
frames: () => Promise.resolve([]), frames: () => Promise.resolve([]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
] ]
......
...@@ -51,7 +51,7 @@ export function usePersistentCacheErrorDetection({ ...@@ -51,7 +51,7 @@ export function usePersistentCacheErrorDetection({
errors, errors,
dispatch, dispatch,
}: { }: {
errors: SupportedErrorEvent[] errors: readonly SupportedErrorEvent[]
dispatch: OverlayDispatch dispatch: OverlayDispatch
}) { }) {
useEffect(() => { useEffect(() => {
......
...@@ -70,20 +70,6 @@ export const WithHydrationWarning: Story = { ...@@ -70,20 +70,6 @@ export const WithHydrationWarning: Story = {
- <p> hello world and welcome to my amazing website with lots of content hello world and welcome to my amazing website with lots of content </p> - <p> hello world and welcome to my amazing website with lots of content hello world and welcome to my amazing website with lots of content </p>
+ <div> hello world and welcome to my amazing website with lots of content hello world and welcome to my amazing website with lots of content </div>`, + <div> hello world and welcome to my amazing website with lots of content hello world and welcome to my amazing website with lots of content </div>`,
}, },
componentStackFrames: [
{
component: 'MyComponent',
file: 'app/page.tsx',
lineNumber: 10,
columnNumber: 5,
},
{
component: 'ParentComponent',
file: 'app/layout.tsx',
lineNumber: 20,
columnNumber: 3,
},
],
}), }),
frames: () => frames: () =>
Promise.resolve([ Promise.resolve([
...@@ -103,6 +89,22 @@ export const WithHydrationWarning: Story = { ...@@ -103,6 +89,22 @@ export const WithHydrationWarning: Story = {
}, },
}, },
]), ]),
componentStackFrames: [
{
component: 'MyComponent',
file: 'app/page.tsx',
line1: 10,
column1: 5,
canOpenInEditor: true,
},
{
component: 'ParentComponent',
file: 'app/layout.tsx',
line1: 20,
column1: 3,
canOpenInEditor: true,
},
],
type: 'runtime', type: 'runtime',
}, },
], ],
......
...@@ -12,8 +12,8 @@ import { usePersistentCacheErrorDetection } from '../../components/errors/error- ...@@ -12,8 +12,8 @@ import { usePersistentCacheErrorDetection } from '../../components/errors/error-
export type SupportedErrorEvent = { export type SupportedErrorEvent = {
id: number id: number
error: Error error: Error
frames: StackFrame[] frames: readonly StackFrame[]
componentStackFrames?: ComponentStackFrame[] componentStackFrames?: readonly ComponentStackFrame[]
type: 'runtime' | 'recoverable' | 'console' type: 'runtime' | 'recoverable' | 'console'
} }
......
...@@ -39,41 +39,40 @@ type FastRefreshState = ...@@ -39,41 +39,40 @@ type FastRefreshState =
/** No refresh in progress. */ /** No refresh in progress. */
| { type: 'idle' } | { type: 'idle' }
/** The refresh process has been triggered, but the new code has not been executed yet. */ /** The refresh process has been triggered, but the new code has not been executed yet. */
| { type: 'pending'; errors: SupportedErrorEvent[] } | { type: 'pending'; errors: readonly SupportedErrorEvent[] }
export interface OverlayState { export interface OverlayState {
nextId: number readonly nextId: number
buildError: string | null readonly buildError: string | null
errors: SupportedErrorEvent[] readonly errors: readonly SupportedErrorEvent[]
refreshState: FastRefreshState readonly refreshState: FastRefreshState
versionInfo: VersionInfo readonly versionInfo: VersionInfo
notFound: boolean readonly notFound: boolean
buildingIndicator: boolean readonly buildingIndicator: boolean
renderingIndicator: boolean readonly renderingIndicator: boolean
staticIndicator: boolean readonly staticIndicator: boolean
showIndicator: boolean readonly showIndicator: boolean
disableDevIndicator: boolean readonly disableDevIndicator: boolean
/** Whether to show the restart server button in the panel UI. Currently /** Whether to show the restart server button in the panel UI. Currently
* only used when Turbopack + Persistent Cache is enabled. * only used when Turbopack + Persistent Cache is enabled.
*/ */
showRestartServerButton: boolean readonly showRestartServerButton: boolean
debugInfo: DebugInfo readonly debugInfo: DebugInfo
routerType: 'pages' | 'app' readonly routerType: 'pages' | 'app'
/** This flag is used to handle the Error Overlay state in the "old" overlay. /** This flag is used to handle the Error Overlay state in the "old" overlay.
* In the DevTools panel, this value will used for the "Error Overlay Mode" * In the DevTools panel, this value will used for the "Error Overlay Mode"
* which is viewing the "Issues Tab" as a fullscreen. * which is viewing the "Issues Tab" as a fullscreen.
*/ */
isErrorOverlayOpen: boolean readonly isErrorOverlayOpen: boolean
devToolsPosition: Corners readonly devToolsPosition: Corners
devToolsPanelPosition: Record<DevtoolsPanelName, Corners> readonly devToolsPanelPosition: Readonly<Record<DevtoolsPanelName, Corners>>
devToolsPanelSize: Record< readonly devToolsPanelSize: Readonly<
DevtoolsPanelName, Record<DevtoolsPanelName, { width: number; height: number }>
{ width: number; height: number }
> >
scale: number readonly scale: number
page: string readonly page: string
theme: 'light' | 'dark' | 'system' readonly theme: 'light' | 'dark' | 'system'
hideShortcut: string | null readonly hideShortcut: string | null
} }
type DevtoolsPanelName = string type DevtoolsPanelName = string
export type OverlayDispatch = React.Dispatch<DispatcherEvent> export type OverlayDispatch = React.Dispatch<DispatcherEvent>
...@@ -325,10 +324,10 @@ export function useErrorOverlayReducer( ...@@ -325,10 +324,10 @@ export function useErrorOverlayReducer(
isRecoverableError: (error: Error) => boolean isRecoverableError: (error: Error) => boolean
) { ) {
function pushErrorFilterDuplicates( function pushErrorFilterDuplicates(
events: SupportedErrorEvent[], events: readonly SupportedErrorEvent[],
id: number, id: number,
error: Error error: Error
): SupportedErrorEvent[] { ): readonly SupportedErrorEvent[] {
const componentStack = getComponentStack(error) const componentStack = getComponentStack(error)
const componentStackFrames = const componentStackFrames =
componentStack === undefined componentStack === undefined
......
...@@ -126,6 +126,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -126,6 +126,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
}, },
...Array(20).fill(ignoredFrame), ...Array(20).fill(ignoredFrame),
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -144,6 +145,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -144,6 +145,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Second error message'), originalCodeFrame: originalCodeFrame('Second error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'console', type: 'console',
}, },
{ {
...@@ -162,6 +164,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -162,6 +164,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Third error message'), originalCodeFrame: originalCodeFrame('Third error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'recoverable', type: 'recoverable',
}, },
{ {
...@@ -180,6 +183,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -180,6 +183,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('typeof window !== undefined'), originalCodeFrame: originalCodeFrame('typeof window !== undefined'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -204,6 +208,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -204,6 +208,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Fifth error message'), originalCodeFrame: originalCodeFrame('Fifth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'console', type: 'console',
}, },
{ {
...@@ -222,6 +227,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -222,6 +227,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Sixth error message'), originalCodeFrame: originalCodeFrame('Sixth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'recoverable', type: 'recoverable',
}, },
{ {
...@@ -240,6 +246,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -240,6 +246,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Sixth error message'), originalCodeFrame: originalCodeFrame('Sixth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -258,6 +265,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -258,6 +265,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Eighth error message'), originalCodeFrame: originalCodeFrame('Eighth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -276,6 +284,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -276,6 +284,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Ninth error message'), originalCodeFrame: originalCodeFrame('Ninth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
{ {
...@@ -294,6 +303,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [ ...@@ -294,6 +303,7 @@ export const runtimeErrors: ReadyRuntimeError[] = [
originalCodeFrame: originalCodeFrame('Tenth error message'), originalCodeFrame: originalCodeFrame('Tenth error message'),
}, },
]), ]),
componentStackFrames: undefined,
type: 'runtime', type: 'runtime',
}, },
] ]
...@@ -9,14 +9,16 @@ export type ReadyRuntimeError = { ...@@ -9,14 +9,16 @@ export type ReadyRuntimeError = {
id: number id: number
runtime: true runtime: true
error: Error & { environmentName?: string } error: Error & { environmentName?: string }
frames: OriginalStackFrame[] | (() => Promise<OriginalStackFrame[]>) frames:
componentStackFrames?: ComponentStackFrame[] | readonly OriginalStackFrame[]
| (() => Promise<readonly OriginalStackFrame[]>)
componentStackFrames: readonly ComponentStackFrame[] | undefined
type: 'runtime' | 'console' | 'recoverable' type: 'runtime' | 'console' | 'recoverable'
} }
export const useFrames = ( export const useFrames = (
error: ReadyRuntimeError | null error: ReadyRuntimeError | null
): OriginalStackFrame[] => { ): readonly OriginalStackFrame[] => {
if (!error) return [] if (!error) return []
if ('use' in React) { if ('use' in React) {
...@@ -28,7 +30,7 @@ export const useFrames = ( ...@@ -28,7 +30,7 @@ export const useFrames = (
) )
} }
return React.use((frames as () => Promise<OriginalStackFrame[]>)()) return React.use((frames as () => Promise<readonly OriginalStackFrame[]>)())
} else { } else {
if (!Array.isArray(error.frames)) { if (!Array.isArray(error.frames)) {
throw new Error( throw new Error(
...@@ -49,6 +51,7 @@ export async function getErrorByType( ...@@ -49,6 +51,7 @@ export async function getErrorByType(
runtime: true, runtime: true,
error: event.error, error: event.error,
type: event.type, type: event.type,
componentStackFrames: event.componentStackFrames,
} as const } as const
if ('use' in React) { if ('use' in React) {
...@@ -63,9 +66,6 @@ export async function getErrorByType( ...@@ -63,9 +66,6 @@ export async function getErrorByType(
) )
}), }),
} }
if (event.componentStackFrames !== undefined) {
readyRuntimeError.componentStackFrames = event.componentStackFrames
}
return readyRuntimeError return readyRuntimeError
} else { } else {
const readyRuntimeError: ReadyRuntimeError = { const readyRuntimeError: ReadyRuntimeError = {
...@@ -77,9 +77,6 @@ export async function getErrorByType( ...@@ -77,9 +77,6 @@ export async function getErrorByType(
isAppDir isAppDir
), ),
} }
if (event.componentStackFrames !== undefined) {
readyRuntimeError.componentStackFrames = event.componentStackFrames
}
return readyRuntimeError return readyRuntimeError
} }
} }
......
...@@ -10,7 +10,7 @@ export interface IgnorableStackFrame extends StackFrame { ...@@ -10,7 +10,7 @@ export interface IgnorableStackFrame extends StackFrame {
} }
export interface OriginalStackFramesRequest { export interface OriginalStackFramesRequest {
frames: StackFrame[] frames: readonly StackFrame[]
isServer: boolean isServer: boolean
isEdgeServer: boolean isEdgeServer: boolean
isAppDirectory: boolean isAppDirectory: boolean
......
...@@ -80,10 +80,10 @@ function getOriginalStackFrame( ...@@ -80,10 +80,10 @@ function getOriginalStackFrame(
} }
export async function getOriginalStackFrames( export async function getOriginalStackFrames(
frames: StackFrame[], frames: readonly StackFrame[],
type: 'server' | 'edge-server' | null, type: 'server' | 'edge-server' | null,
isAppDir: boolean isAppDir: boolean
): Promise<OriginalStackFrame[]> { ): Promise<readonly OriginalStackFrame[]> {
const req: OriginalStackFramesRequest = { const req: OriginalStackFramesRequest = {
frames, frames,
isServer: type === 'server', isServer: type === 'server',
......
...@@ -482,7 +482,7 @@ export async function getOriginalStackFrames({ ...@@ -482,7 +482,7 @@ export async function getOriginalStackFrames({
}: { }: {
project: Project project: Project
projectPath: string projectPath: string
frames: StackFrame[] frames: readonly StackFrame[]
isServer: boolean isServer: boolean
isEdgeServer: boolean isEdgeServer: boolean
isAppDirectory: boolean isAppDirectory: boolean
......
...@@ -384,7 +384,7 @@ export async function getOriginalStackFrames({ ...@@ -384,7 +384,7 @@ export async function getOriginalStackFrames({
isServer: boolean isServer: boolean
isEdgeServer: boolean isEdgeServer: boolean
isAppDirectory: boolean isAppDirectory: boolean
frames: StackFrame[] frames: readonly StackFrame[]
clientStats: () => webpack.Stats | null clientStats: () => webpack.Stats | null
serverStats: () => webpack.Stats | null serverStats: () => webpack.Stats | null
edgeServerStats: () => webpack.Stats | null edgeServerStats: () => webpack.Stats | null
......
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