Skip to content

Commit 34f29fb

Browse files
committed
[dev-overlay] Move build indicator into Dev Overlay state
1 parent e18b90d commit 34f29fb

File tree

15 files changed

+61
-119
lines changed

15 files changed

+61
-119
lines changed

packages/next/src/client/app-next-dev.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import './app-webpack'
44

55
import { appBootstrap } from './app-bootstrap'
6-
import { initializeDevBuildIndicatorForAppRouter } from './dev/dev-build-indicator/initialize-for-app-router'
76

87
const instrumentationHooks = require('../lib/require-instrumentation-client')
98

109
appBootstrap(() => {
1110
const { hydrate } = require('./app-index')
1211
hydrate(instrumentationHooks)
13-
initializeDevBuildIndicatorForAppRouter()
1412
})

packages/next/src/client/app-next-turbopack.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,4 @@ const instrumentationHooks = require('../lib/require-instrumentation-client')
1010
appBootstrap(() => {
1111
const { hydrate } = require('./app-index')
1212
hydrate(instrumentationHooks)
13-
14-
if (process.env.NODE_ENV !== 'production') {
15-
const { initializeDevBuildIndicatorForAppRouter } =
16-
require('./dev/dev-build-indicator/initialize-for-app-router') as typeof import('./dev/dev-build-indicator/initialize-for-app-router')
17-
initializeDevBuildIndicatorForAppRouter()
18-
}
1913
})

packages/next/src/client/components/react-dev-overlay/app/hot-reloader-client.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import formatWebpackMessages from '../utils/format-webpack-messages'
77
import { useRouter } from '../../navigation'
88
import {
99
ACTION_BEFORE_REFRESH,
10+
ACTION_BUILDING_INDICATOR_HIDE,
1011
ACTION_BUILD_ERROR,
1112
ACTION_BUILD_OK,
13+
ACTION_BUILDING_INDICATOR_SHOW,
1214
ACTION_DEBUG_INFO,
1315
ACTION_DEV_INDICATOR,
1416
ACTION_ERROR_OVERLAY_OPEN,
@@ -39,7 +41,6 @@ import type {
3941
import { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from '../shared'
4042
import type { DebugInfo } from '../types'
4143
import { useUntrackedPathname } from '../../navigation-untracked'
42-
import { handleDevBuildIndicatorHmrEvents } from '../../../dev/dev-build-indicator/internal/handle-dev-build-indicator-hmr-events'
4344
import type { GlobalErrorComponent } from '../../global-error'
4445
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
4546
import reportHmrLatency from '../utils/report-hmr-latency'
@@ -60,6 +61,8 @@ export interface Dispatcher {
6061
onUnhandledError(error: Error): void
6162
onUnhandledRejection(error: Error): void
6263
openErrorOverlay(): void
64+
buildingIndicatorHide(): void
65+
buildingIndicatorShow(): void
6366
}
6467

6568
let mostRecentCompilationHash: any = null
@@ -301,6 +304,8 @@ function processMessage(
301304
break
302305
}
303306
case HMR_ACTIONS_SENT_TO_BROWSER.BUILDING: {
307+
dispatcher.buildingIndicatorShow()
308+
304309
if (process.env.TURBOPACK) {
305310
turbopackHmr!.onBuilding()
306311
} else {
@@ -312,6 +317,8 @@ function processMessage(
312317
}
313318
case HMR_ACTIONS_SENT_TO_BROWSER.BUILT:
314319
case HMR_ACTIONS_SENT_TO_BROWSER.SYNC: {
320+
dispatcher.buildingIndicatorHide()
321+
315322
if (obj.hash) {
316323
handleAvailableHash(obj.hash)
317324
}
@@ -533,6 +540,12 @@ export default function HotReload({
533540
openErrorOverlay() {
534541
dispatch({ type: ACTION_ERROR_OVERLAY_OPEN })
535542
},
543+
buildingIndicatorHide() {
544+
dispatch({ type: ACTION_BUILDING_INDICATOR_HIDE })
545+
},
546+
buildingIndicatorShow() {
547+
dispatch({ type: ACTION_BUILDING_INDICATOR_SHOW })
548+
},
536549
}
537550
}, [dispatch])
538551

@@ -594,7 +607,6 @@ export default function HotReload({
594607
const handler = (event: MessageEvent<any>) => {
595608
try {
596609
const obj = JSON.parse(event.data)
597-
handleDevBuildIndicatorHmrEvents(obj)
598610
processMessage(
599611
obj,
600612
sendMessage,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
} from './hydration-error-state'
66
import {
77
ACTION_BEFORE_REFRESH,
8+
ACTION_BUILDING_INDICATOR_HIDE,
89
ACTION_BUILD_ERROR,
910
ACTION_BUILD_OK,
11+
ACTION_BUILDING_INDICATOR_SHOW,
1012
ACTION_DEV_INDICATOR,
1113
ACTION_REFRESH,
1214
ACTION_STATIC_INDICATOR,
@@ -115,5 +117,13 @@ export function onDevIndicator(devIndicatorsState: DevIndicatorServerState) {
115117
Bus.emit({ type: ACTION_DEV_INDICATOR, devIndicator: devIndicatorsState })
116118
}
117119

120+
export function buildingIndicatorShow() {
121+
Bus.emit({ type: ACTION_BUILDING_INDICATOR_SHOW })
122+
}
123+
124+
export function buildingIndicatorHide() {
125+
Bus.emit({ type: ACTION_BUILDING_INDICATOR_HIDE })
126+
}
127+
118128
export { getErrorByType } from '../utils/get-error-by-type'
119129
export { getServerError } from '../utils/node-stack-frames'

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import {
4141
onVersionInfo,
4242
onStaticIndicator,
4343
onDevIndicator,
44+
buildingIndicatorHide,
45+
buildingIndicatorShow,
4446
} from './client'
4547
import stripAnsi from 'next/dist/compiled/strip-ansi'
4648
import { addMessageListener, sendMessage } from './websocket'
@@ -272,6 +274,8 @@ function processMessage(obj: HMR_ACTION_TYPES) {
272274
break
273275
}
274276
case HMR_ACTIONS_SENT_TO_BROWSER.BUILDING: {
277+
buildingIndicatorShow()
278+
275279
if (process.env.TURBOPACK) {
276280
turbopackHmr!.onBuilding()
277281
} else {
@@ -282,6 +286,8 @@ function processMessage(obj: HMR_ACTION_TYPES) {
282286
}
283287
case HMR_ACTIONS_SENT_TO_BROWSER.BUILT:
284288
case HMR_ACTIONS_SENT_TO_BROWSER.SYNC: {
289+
buildingIndicatorHide()
290+
285291
if (obj.hash) handleAvailableHash(obj.hash)
286292

287293
const { errors, warnings } = obj

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface OverlayState {
2121
refreshState: FastRefreshState
2222
versionInfo: VersionInfo
2323
notFound: boolean
24+
buildingIndicator: boolean
2425
staticIndicator: boolean
2526
showIndicator: boolean
2627
disableDevIndicator: boolean
@@ -43,6 +44,8 @@ export const ACTION_DEV_INDICATOR = 'dev-indicator'
4344
export const ACTION_ERROR_OVERLAY_OPEN = 'error-overlay-open'
4445
export const ACTION_ERROR_OVERLAY_CLOSE = 'error-overlay-close'
4546
export const ACTION_ERROR_OVERLAY_TOGGLE = 'error-overlay-toggle'
47+
export const ACTION_BUILDING_INDICATOR_SHOW = 'building-indicator-show'
48+
export const ACTION_BUILDING_INDICATOR_HIDE = 'building-indicator-hide'
4649

4750
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
4851
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
@@ -101,6 +104,13 @@ export interface ErrorOverlayToggleAction {
101104
type: typeof ACTION_ERROR_OVERLAY_TOGGLE
102105
}
103106

107+
export interface BuildingIndicatorShowAction {
108+
type: typeof ACTION_BUILDING_INDICATOR_SHOW
109+
}
110+
export interface BuildingIndicatorHideAction {
111+
type: typeof ACTION_BUILDING_INDICATOR_HIDE
112+
}
113+
104114
export type BusEvent =
105115
| BuildOkAction
106116
| BuildErrorAction
@@ -115,6 +125,8 @@ export type BusEvent =
115125
| ErrorOverlayOpenAction
116126
| ErrorOverlayCloseAction
117127
| ErrorOverlayToggleAction
128+
| BuildingIndicatorShowAction
129+
| BuildingIndicatorHideAction
118130

119131
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
120132
// 1st group: v8
@@ -148,6 +160,7 @@ export const INITIAL_OVERLAY_STATE: Omit<
148160
*/
149161
showIndicator: false,
150162
disableDevIndicator: false,
163+
buildingIndicator: false,
151164
refreshState: { type: 'idle' },
152165
versionInfo: { installed: '0.0.0', staleness: 'unknown' },
153166
debugInfo: { devtoolsFrontendUrl: undefined },
@@ -289,6 +302,12 @@ export function useErrorOverlayReducer(
289302
case ACTION_ERROR_OVERLAY_TOGGLE: {
290303
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
291304
}
305+
case ACTION_BUILDING_INDICATOR_SHOW: {
306+
return { ...state, buildingIndicator: true }
307+
}
308+
case ACTION_BUILDING_INDICATOR_HIDE: {
309+
return { ...state, buildingIndicator: false }
310+
}
292311
default: {
293312
return state
294313
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const state: OverlayState = {
5454
showIndicator: true,
5555
versionInfo: mockVersionInfo,
5656
notFound: false,
57+
buildingIndicator: false,
5758
staticIndicator: true,
5859
debugInfo: { devtoolsFrontendUrl: undefined },
5960
isErrorOverlayOpen: false,

packages/next/src/client/components/react-dev-overlay/ui/components/errors/dev-tools-indicator/dev-tools-indicator.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { useState, useEffect, useRef, createContext, useContext } from 'react'
1111
import { Toast } from '../../toast'
1212
import { NextLogo } from './next-logo'
13-
import { useIsDevBuilding } from '../../../../../../dev/dev-build-indicator/internal/initialize'
1413
import { useIsDevRendering } from '../../../../utils/dev-indicator/dev-render-indicator'
1514
import { useDelayedRender } from '../../../hooks/use-delayed-render'
1615
import { TurbopackInfo } from './dev-tools-info/turbopack-info'
@@ -54,6 +53,7 @@ export function DevToolsIndicator({
5453
routerType={state.routerType}
5554
semver={state.versionInfo.installed}
5655
issueCount={errorCount}
56+
isDevBuilding={state.buildingIndicator}
5757
isStaticRoute={state.staticIndicator}
5858
hide={() => {
5959
setIsDevToolsIndicatorVisible(false)
@@ -95,6 +95,7 @@ function DevToolsPopover({
9595
routerType,
9696
disabled,
9797
issueCount,
98+
isDevBuilding,
9899
isStaticRoute,
99100
isTurbopack,
100101
isBuildError,
@@ -108,6 +109,7 @@ function DevToolsPopover({
108109
issueCount: number
109110
isStaticRoute: boolean
110111
semver: string | undefined
112+
isDevBuilding: boolean
111113
isTurbopack: boolean
112114
isBuildError: boolean
113115
hide: () => void
@@ -291,7 +293,7 @@ function DevToolsPopover({
291293
issueCount={issueCount}
292294
onTriggerClick={onTriggerClick}
293295
toggleErrorOverlay={toggleErrorOverlay}
294-
isDevBuilding={useIsDevBuilding()}
296+
isDevBuilding={isDevBuilding}
295297
isDevRendering={useIsDevRendering()}
296298
isBuildError={isBuildError}
297299
scale={scale}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const initialState: OverlayState = {
7070
],
7171
refreshState: { type: 'idle' },
7272
notFound: false,
73+
buildingIndicator: false,
7374
staticIndicator: false,
7475
debugInfo: { devtoolsFrontendUrl: undefined },
7576
versionInfo: {

packages/next/src/client/dev/dev-build-indicator/initialize-for-app-router.ts

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

0 commit comments

Comments
 (0)