Skip to content

Commit a751865

Browse files
committed
[dev-overlay] Remove unused code
1 parent f9d18a1 commit a751865

File tree

4 files changed

+98
-181
lines changed

4 files changed

+98
-181
lines changed

packages/next/src/client/components/errors/hydration-error-info.ts

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

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

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

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

Lines changed: 96 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface OverlayState {
3030
routerType: 'pages' | 'app'
3131
isErrorOverlayOpen: boolean
3232
}
33-
export type OverlayDispatch = React.Dispatch<BusEvent>
33+
export type OverlayDispatch = React.Dispatch<DispatcherEvent>
3434

3535
export const ACTION_STATIC_INDICATOR = 'static-indicator'
3636
export const ACTION_BUILD_OK = 'build-ok'
@@ -121,7 +121,7 @@ export interface RenderingIndicatorHideAction {
121121
type: typeof ACTION_RENDERING_INDICATOR_HIDE
122122
}
123123

124-
export type BusEvent =
124+
export type DispatcherEvent =
125125
| BuildOkAction
126126
| BuildErrorAction
127127
| BeforeFastRefreshAction
@@ -235,107 +235,110 @@ export function useErrorOverlayReducer(
235235
return pendingEvents
236236
}
237237

238-
return useReducer((state: OverlayState, action: BusEvent): OverlayState => {
239-
switch (action.type) {
240-
case ACTION_DEBUG_INFO: {
241-
return { ...state, debugInfo: action.debugInfo }
242-
}
243-
case ACTION_STATIC_INDICATOR: {
244-
return { ...state, staticIndicator: action.staticIndicator }
245-
}
246-
case ACTION_BUILD_OK: {
247-
return { ...state, buildError: null }
248-
}
249-
case ACTION_BUILD_ERROR: {
250-
return { ...state, buildError: action.message }
251-
}
252-
case ACTION_BEFORE_REFRESH: {
253-
return { ...state, refreshState: { type: 'pending', errors: [] } }
254-
}
255-
case ACTION_REFRESH: {
256-
return {
257-
...state,
258-
buildError: null,
259-
errors:
260-
// Errors can come in during updates. In this case, UNHANDLED_ERROR
261-
// and UNHANDLED_REJECTION events might be dispatched between the
262-
// BEFORE_REFRESH and the REFRESH event. We want to keep those errors
263-
// around until the next refresh. Otherwise we run into a race
264-
// condition where those errors would be cleared on refresh completion
265-
// before they can be displayed.
266-
state.refreshState.type === 'pending'
267-
? state.refreshState.errors
268-
: [],
269-
refreshState: { type: 'idle' },
238+
return useReducer(
239+
(state: OverlayState, action: DispatcherEvent): OverlayState => {
240+
switch (action.type) {
241+
case ACTION_DEBUG_INFO: {
242+
return { ...state, debugInfo: action.debugInfo }
270243
}
271-
}
272-
case ACTION_UNHANDLED_ERROR:
273-
case ACTION_UNHANDLED_REJECTION: {
274-
switch (state.refreshState.type) {
275-
case 'idle': {
276-
return {
277-
...state,
278-
nextId: state.nextId + 1,
279-
errors: pushErrorFilterDuplicates(
280-
state.errors,
281-
state.nextId,
282-
action.reason
283-
),
284-
}
244+
case ACTION_STATIC_INDICATOR: {
245+
return { ...state, staticIndicator: action.staticIndicator }
246+
}
247+
case ACTION_BUILD_OK: {
248+
return { ...state, buildError: null }
249+
}
250+
case ACTION_BUILD_ERROR: {
251+
return { ...state, buildError: action.message }
252+
}
253+
case ACTION_BEFORE_REFRESH: {
254+
return { ...state, refreshState: { type: 'pending', errors: [] } }
255+
}
256+
case ACTION_REFRESH: {
257+
return {
258+
...state,
259+
buildError: null,
260+
errors:
261+
// Errors can come in during updates. In this case, UNHANDLED_ERROR
262+
// and UNHANDLED_REJECTION events might be dispatched between the
263+
// BEFORE_REFRESH and the REFRESH event. We want to keep those errors
264+
// around until the next refresh. Otherwise we run into a race
265+
// condition where those errors would be cleared on refresh completion
266+
// before they can be displayed.
267+
state.refreshState.type === 'pending'
268+
? state.refreshState.errors
269+
: [],
270+
refreshState: { type: 'idle' },
285271
}
286-
case 'pending': {
287-
return {
288-
...state,
289-
nextId: state.nextId + 1,
290-
refreshState: {
291-
...state.refreshState,
272+
}
273+
case ACTION_UNHANDLED_ERROR:
274+
case ACTION_UNHANDLED_REJECTION: {
275+
switch (state.refreshState.type) {
276+
case 'idle': {
277+
return {
278+
...state,
279+
nextId: state.nextId + 1,
292280
errors: pushErrorFilterDuplicates(
293281
state.errors,
294282
state.nextId,
295283
action.reason
296284
),
297-
},
285+
}
286+
}
287+
case 'pending': {
288+
return {
289+
...state,
290+
nextId: state.nextId + 1,
291+
refreshState: {
292+
...state.refreshState,
293+
errors: pushErrorFilterDuplicates(
294+
state.errors,
295+
state.nextId,
296+
action.reason
297+
),
298+
},
299+
}
298300
}
301+
default:
302+
return state
299303
}
300-
default:
301-
return state
302304
}
303-
}
304-
case ACTION_VERSION_INFO: {
305-
return { ...state, versionInfo: action.versionInfo }
306-
}
307-
case ACTION_DEV_INDICATOR: {
308-
return {
309-
...state,
310-
showIndicator: true,
311-
disableDevIndicator:
312-
shouldDisableDevIndicator || !!action.devIndicator.disabledUntil,
305+
case ACTION_VERSION_INFO: {
306+
return { ...state, versionInfo: action.versionInfo }
307+
}
308+
case ACTION_DEV_INDICATOR: {
309+
return {
310+
...state,
311+
showIndicator: true,
312+
disableDevIndicator:
313+
shouldDisableDevIndicator || !!action.devIndicator.disabledUntil,
314+
}
315+
}
316+
case ACTION_ERROR_OVERLAY_OPEN: {
317+
return { ...state, isErrorOverlayOpen: true }
318+
}
319+
case ACTION_ERROR_OVERLAY_CLOSE: {
320+
return { ...state, isErrorOverlayOpen: false }
321+
}
322+
case ACTION_ERROR_OVERLAY_TOGGLE: {
323+
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
324+
}
325+
case ACTION_BUILDING_INDICATOR_SHOW: {
326+
return { ...state, buildingIndicator: true }
327+
}
328+
case ACTION_BUILDING_INDICATOR_HIDE: {
329+
return { ...state, buildingIndicator: false }
330+
}
331+
case ACTION_RENDERING_INDICATOR_SHOW: {
332+
return { ...state, renderingIndicator: true }
333+
}
334+
case ACTION_RENDERING_INDICATOR_HIDE: {
335+
return { ...state, renderingIndicator: false }
336+
}
337+
default: {
338+
return state
313339
}
314340
}
315-
case ACTION_ERROR_OVERLAY_OPEN: {
316-
return { ...state, isErrorOverlayOpen: true }
317-
}
318-
case ACTION_ERROR_OVERLAY_CLOSE: {
319-
return { ...state, isErrorOverlayOpen: false }
320-
}
321-
case ACTION_ERROR_OVERLAY_TOGGLE: {
322-
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
323-
}
324-
case ACTION_BUILDING_INDICATOR_SHOW: {
325-
return { ...state, buildingIndicator: true }
326-
}
327-
case ACTION_BUILDING_INDICATOR_HIDE: {
328-
return { ...state, buildingIndicator: false }
329-
}
330-
case ACTION_RENDERING_INDICATOR_SHOW: {
331-
return { ...state, renderingIndicator: true }
332-
}
333-
case ACTION_RENDERING_INDICATOR_HIDE: {
334-
return { ...state, renderingIndicator: false }
335-
}
336-
default: {
337-
return state
338-
}
339-
}
340-
}, getInitialState(routerType))
341+
},
342+
getInitialState(routerType)
343+
)
341344
}

packages/next/src/client/components/react-dev-overlay/ui/dev-overlay.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Meta, StoryObj } from '@storybook/react'
2-
import type { BusEvent, OverlayState } from '../shared'
2+
import type { DispatcherEvent, OverlayState } from '../shared'
33

44
// @ts-expect-error
55
import imgApp from './app.png'
@@ -97,7 +97,7 @@ const initialState: OverlayState = {
9797
}
9898

9999
function useOverlayReducer() {
100-
return useReducer<OverlayState, [BusEvent]>((state, action): OverlayState => {
100+
return useReducer<OverlayState, [DispatcherEvent]>((state, action): OverlayState => {
101101
switch (action.type) {
102102
case ACTION_ERROR_OVERLAY_CLOSE: {
103103
return { ...state, isErrorOverlayOpen: false }

0 commit comments

Comments
 (0)