Skip to content

Commit 4ad649d

Browse files
committed
[dev-overlay] Remove unused code
1 parent d0fb5ee commit 4ad649d

File tree

4 files changed

+116
-196
lines changed

4 files changed

+116
-196
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
@@ -240,107 +240,110 @@ export function useErrorOverlayReducer(
240240
return events
241241
}
242242

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

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

Lines changed: 20 additions & 17 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,23 +97,26 @@ const initialState: OverlayState = {
9797
}
9898

9999
function useOverlayReducer() {
100-
return useReducer<OverlayState, [BusEvent]>((state, action): OverlayState => {
101-
switch (action.type) {
102-
case ACTION_ERROR_OVERLAY_CLOSE: {
103-
return { ...state, isErrorOverlayOpen: false }
100+
return useReducer<OverlayState, [DispatcherEvent]>(
101+
(state, action): OverlayState => {
102+
switch (action.type) {
103+
case ACTION_ERROR_OVERLAY_CLOSE: {
104+
return { ...state, isErrorOverlayOpen: false }
105+
}
106+
case ACTION_ERROR_OVERLAY_OPEN: {
107+
return { ...state, isErrorOverlayOpen: true }
108+
}
109+
case ACTION_ERROR_OVERLAY_TOGGLE: {
110+
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
111+
}
112+
default: {
113+
return state
114+
}
104115
}
105-
case ACTION_ERROR_OVERLAY_OPEN: {
106-
return { ...state, isErrorOverlayOpen: true }
107-
}
108-
case ACTION_ERROR_OVERLAY_TOGGLE: {
109-
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
110-
}
111-
default: {
112-
return state
113-
}
114-
}
115-
return state
116-
}, initialState)
116+
return state
117+
},
118+
initialState
119+
)
117120
}
118121

119122
function getNoSquashedHydrationErrorDetails() {

0 commit comments

Comments
 (0)