Skip to content

Commit 69aa179

Browse files
committed
[dev-overlay] Move build indicator into Dev Overlay state
1 parent af8e8fe commit 69aa179

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,
@@ -40,7 +42,6 @@ import type {
4042
import { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from '../shared'
4143
import type { DebugInfo } from '../types'
4244
import { useUntrackedPathname } from '../../navigation-untracked'
43-
import { handleDevBuildIndicatorHmrEvents } from '../../../dev/dev-build-indicator/internal/handle-dev-build-indicator-hmr-events'
4445
import type { GlobalErrorComponent } from '../../global-error'
4546
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
4647
import reportHmrLatency from '../utils/report-hmr-latency'
@@ -61,6 +62,8 @@ export interface Dispatcher {
6162
onUnhandledError(error: Error): void
6263
onUnhandledRejection(error: Error): void
6364
openErrorOverlay(): void
65+
buildingIndicatorHide(): void
66+
buildingIndicatorShow(): void
6467
}
6568

6669
let mostRecentCompilationHash: any = null
@@ -302,6 +305,8 @@ function processMessage(
302305
break
303306
}
304307
case HMR_ACTIONS_SENT_TO_BROWSER.BUILDING: {
308+
dispatcher.buildingIndicatorShow()
309+
305310
if (process.env.TURBOPACK) {
306311
turbopackHmr!.onBuilding()
307312
} else {
@@ -313,6 +318,8 @@ function processMessage(
313318
}
314319
case HMR_ACTIONS_SENT_TO_BROWSER.BUILT:
315320
case HMR_ACTIONS_SENT_TO_BROWSER.SYNC: {
321+
dispatcher.buildingIndicatorHide()
322+
316323
if (obj.hash) {
317324
handleAvailableHash(obj.hash)
318325
}
@@ -535,6 +542,12 @@ export default function HotReload({
535542
openErrorOverlay() {
536543
dispatch({ type: ACTION_ERROR_OVERLAY_OPEN })
537544
},
545+
buildingIndicatorHide() {
546+
dispatch({ type: ACTION_BUILDING_INDICATOR_HIDE })
547+
},
548+
buildingIndicatorShow() {
549+
dispatch({ type: ACTION_BUILDING_INDICATOR_SHOW })
550+
},
538551
}
539552
}, [dispatch])
540553

@@ -596,7 +609,6 @@ export default function HotReload({
596609
const handler = (event: MessageEvent<any>) => {
597610
try {
598611
const obj = JSON.parse(event.data)
599-
handleDevBuildIndicatorHmrEvents(obj)
600612
processMessage(
601613
obj,
602614
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
@@ -22,6 +22,7 @@ export interface OverlayState {
2222
refreshState: FastRefreshState
2323
versionInfo: VersionInfo
2424
notFound: boolean
25+
buildingIndicator: boolean
2526
staticIndicator: boolean
2627
showIndicator: boolean
2728
disableDevIndicator: boolean
@@ -44,6 +45,8 @@ export const ACTION_DEV_INDICATOR = 'dev-indicator'
4445
export const ACTION_ERROR_OVERLAY_OPEN = 'error-overlay-open'
4546
export const ACTION_ERROR_OVERLAY_CLOSE = 'error-overlay-close'
4647
export const ACTION_ERROR_OVERLAY_TOGGLE = 'error-overlay-toggle'
48+
export const ACTION_BUILDING_INDICATOR_SHOW = 'building-indicator-show'
49+
export const ACTION_BUILDING_INDICATOR_HIDE = 'building-indicator-hide'
4750

4851
export const STORAGE_KEY_THEME = '__nextjs-dev-tools-theme'
4952
export const STORAGE_KEY_POSITION = '__nextjs-dev-tools-position'
@@ -102,6 +105,13 @@ export interface ErrorOverlayToggleAction {
102105
type: typeof ACTION_ERROR_OVERLAY_TOGGLE
103106
}
104107

108+
export interface BuildingIndicatorShowAction {
109+
type: typeof ACTION_BUILDING_INDICATOR_SHOW
110+
}
111+
export interface BuildingIndicatorHideAction {
112+
type: typeof ACTION_BUILDING_INDICATOR_HIDE
113+
}
114+
105115
export type BusEvent =
106116
| BuildOkAction
107117
| BuildErrorAction
@@ -116,6 +126,8 @@ export type BusEvent =
116126
| ErrorOverlayOpenAction
117127
| ErrorOverlayCloseAction
118128
| ErrorOverlayToggleAction
129+
| BuildingIndicatorShowAction
130+
| BuildingIndicatorHideAction
119131

120132
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
121133
// 1st group: v8
@@ -149,6 +161,7 @@ export const INITIAL_OVERLAY_STATE: Omit<
149161
*/
150162
showIndicator: false,
151163
disableDevIndicator: false,
164+
buildingIndicator: false,
152165
refreshState: { type: 'idle' },
153166
versionInfo: { installed: '0.0.0', staleness: 'unknown' },
154167
debugInfo: { devtoolsFrontendUrl: undefined },
@@ -296,6 +309,12 @@ export function useErrorOverlayReducer(
296309
case ACTION_ERROR_OVERLAY_TOGGLE: {
297310
return { ...state, isErrorOverlayOpen: !state.isErrorOverlayOpen }
298311
}
312+
case ACTION_BUILDING_INDICATOR_SHOW: {
313+
return { ...state, buildingIndicator: true }
314+
}
315+
case ACTION_BUILDING_INDICATOR_HIDE: {
316+
return { ...state, buildingIndicator: false }
317+
}
299318
default: {
300319
return state
301320
}

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
@@ -73,6 +73,7 @@ const initialState: OverlayState = {
7373
],
7474
refreshState: { type: 'idle' },
7575
notFound: false,
76+
buildingIndicator: false,
7677
staticIndicator: false,
7778
debugInfo: { devtoolsFrontendUrl: undefined },
7879
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)