Skip to content

Commit d3575aa

Browse files
committed
[dev-tools] refactor: use global server state
1 parent bb3284b commit d3575aa

File tree

9 files changed

+28
-25
lines changed

9 files changed

+28
-25
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { useUntrackedPathname } from '../../navigation-untracked'
4343
import { getComponentStack, getOwnerStack } from '../../errors/stitched-error'
4444
import { handleDevBuildIndicatorHmrEvents } from '../../../dev/dev-build-indicator/internal/handle-dev-build-indicator-hmr-events'
4545
import type { GlobalErrorComponent } from '../../global-error'
46-
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
46+
import type { DevToolsServerState } from '../../../../server/dev/dev-tools-server-state'
4747
import reportHmrLatency from '../utils/report-hmr-latency'
4848
import { TurbopackHmr } from '../utils/turbopack-hot-reloader-common'
4949
import { NEXT_HMR_REFRESH_HASH_COOKIE } from '../../app-router-headers'
@@ -56,7 +56,7 @@ export interface Dispatcher {
5656
onBeforeRefresh(): void
5757
onRefresh(): void
5858
onStaticIndicator(status: boolean): void
59-
onDevIndicator(devIndicator: DevIndicatorServerState): void
59+
onDevIndicator(devIndicator: DevToolsServerState['devIndicator']): void
6060
}
6161

6262
let mostRecentCompilationHash: any = null

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '../shared'
1919
import type { VersionInfo } from '../../../../server/dev/parse-version-info'
2020
import { getComponentStack, getOwnerStack } from '../../errors/stitched-error'
21-
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
21+
import type { DevToolsServerState } from '../../../../server/dev/dev-tools-server-state'
2222

2323
let isRegistered = false
2424

@@ -126,8 +126,10 @@ export function onStaticIndicator(isStatic: boolean) {
126126
Bus.emit({ type: ACTION_STATIC_INDICATOR, staticIndicator: isStatic })
127127
}
128128

129-
export function onDevIndicator(devIndicatorsState: DevIndicatorServerState) {
130-
Bus.emit({ type: ACTION_DEV_INDICATOR, devIndicator: devIndicatorsState })
129+
export function onDevIndicator(
130+
devIndicator: DevToolsServerState['devIndicator']
131+
) {
132+
Bus.emit({ type: ACTION_DEV_INDICATOR, devIndicator })
131133
}
132134

133135
export { getErrorByType } from '../utils/get-error-by-type'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { VersionInfo } from '../../../server/dev/parse-version-info'
55
import type { SupportedErrorEvent } from './ui/container/runtime-error/render-error'
66
import type { ComponentStackFrame } from './utils/parse-component-stack'
77
import type { DebugInfo } from './types'
8-
import type { DevIndicatorServerState } from '../../../server/dev/dev-indicator-server-state'
8+
import type { DevToolsServerState } from '../../../server/dev/dev-tools-server-state'
99
import type { HMR_ACTION_TYPES } from '../../../server/dev/hot-reloader-types'
1010
import { getOwnerStack } from '../errors/stitched-error'
1111

@@ -87,7 +87,7 @@ interface VersionInfoAction {
8787

8888
interface DevIndicatorAction {
8989
type: typeof ACTION_DEV_INDICATOR
90-
devIndicator: DevIndicatorServerState
90+
devIndicator: DevToolsServerState['devIndicator']
9191
}
9292

9393
export type BusEvent =

packages/next/src/server/dev/dev-indicator-middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ServerResponse, IncomingMessage } from 'http'
22
import { middlewareResponse } from '../../client/components/react-dev-overlay/server/middleware-response'
33
import * as Log from '../../build/output/log'
4-
import { devIndicatorServerState } from './dev-indicator-server-state'
4+
import { devToolsServerState } from './dev-tools-server-state'
55

66
const DISABLE_DEV_INDICATOR_PREFIX = '/__nextjs_disable_dev_indicator'
77

@@ -27,7 +27,8 @@ export function getDisableDevIndicatorMiddleware() {
2727
return middlewareResponse.methodNotAllowed(res)
2828
}
2929

30-
devIndicatorServerState.disabledUntil = Date.now() + COOLDOWN_TIME_MS
30+
devToolsServerState.devIndicator.disabledUntil =
31+
Date.now() + COOLDOWN_TIME_MS
3132

3233
return middlewareResponse.noContent(res)
3334
} catch (err) {

packages/next/src/server/dev/dev-indicator-server-state.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type DevToolsServerState = typeof devToolsServerState
2+
3+
export const devToolsServerState = {
4+
devIndicator: { disabledUntil: 0 },
5+
}

packages/next/src/server/dev/hot-middleware.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { isMiddlewareFilename } from '../../build/utils'
2727
import type { VersionInfo } from './parse-version-info'
2828
import type { HMR_ACTION_TYPES } from './hot-reloader-types'
2929
import { HMR_ACTIONS_SENT_TO_BROWSER } from './hot-reloader-types'
30-
import { devIndicatorServerState } from './dev-indicator-server-state'
30+
import { devToolsServerState } from './dev-tools-server-state'
3131

3232
function isMiddlewareStats(stats: webpack.Stats) {
3333
for (const key of stats.compilation.entrypoints.keys()) {
@@ -203,8 +203,8 @@ export class WebpackHotMiddleware {
203203
const stats = statsToJson(syncStats)
204204
const middlewareStats = statsToJson(this.middlewareLatestStats?.stats)
205205

206-
if (devIndicatorServerState.disabledUntil < Date.now()) {
207-
devIndicatorServerState.disabledUntil = 0
206+
if (devToolsServerState.devIndicator.disabledUntil < Date.now()) {
207+
devToolsServerState.devIndicator.disabledUntil = 0
208208
}
209209

210210
this.publish({
@@ -219,7 +219,7 @@ export class WebpackHotMiddleware {
219219
debug: {
220220
devtoolsFrontendUrl: this.devtoolsFrontendUrl,
221221
},
222-
devIndicator: devIndicatorServerState,
222+
devIndicator: devToolsServerState.devIndicator,
223223
})
224224
}
225225
}

packages/next/src/server/dev/hot-reloader-turbopack.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import {
9595
type TopLevelIssuesMap,
9696
} from '../../shared/lib/turbopack/utils'
9797
import { getDevOverlayFontMiddleware } from '../../client/components/react-dev-overlay/font/get-dev-overlay-font-middleware'
98-
import { devIndicatorServerState } from './dev-indicator-server-state'
98+
import { devToolsServerState } from './dev-tools-server-state'
9999
import { getDisableDevIndicatorMiddleware } from './dev-indicator-middleware'
100100
import { getRestartDevServerMiddleware } from '../../client/components/react-dev-overlay/server/restart-dev-server-middleware'
101101
// import { getSupportedBrowsers } from '../../build/utils'
@@ -839,8 +839,8 @@ export async function createHotReloaderTurbopack(
839839
}
840840
}
841841

842-
if (devIndicatorServerState.disabledUntil < Date.now()) {
843-
devIndicatorServerState.disabledUntil = 0
842+
if (devToolsServerState.devIndicator.disabledUntil < Date.now()) {
843+
devToolsServerState.devIndicator.disabledUntil = 0
844844
}
845845

846846
;(async function () {
@@ -855,7 +855,7 @@ export async function createHotReloaderTurbopack(
855855
debug: {
856856
devtoolsFrontendUrl,
857857
},
858-
devIndicator: devIndicatorServerState,
858+
devIndicator: devToolsServerState.devIndicator,
859859
}
860860

861861
sendToClient(client, sync)

packages/next/src/server/dev/hot-reloader-types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { RouteDefinition } from '../route-definitions/route-definition'
77
import type { Project, Update as TurbopackUpdate } from '../../build/swc/types'
88
import type { VersionInfo } from './parse-version-info'
99
import type { DebugInfo } from '../../client/components/react-dev-overlay/types'
10-
import type { DevIndicatorServerState } from './dev-indicator-server-state'
10+
import type { DevToolsServerState } from './dev-tools-server-state'
1111

1212
export const enum HMR_ACTIONS_SENT_TO_BROWSER {
1313
ADDED_PAGE = 'addedPage',
@@ -57,7 +57,7 @@ export interface SyncAction {
5757
versionInfo: VersionInfo
5858
updatedModules?: ReadonlyArray<string>
5959
debug?: DebugInfo
60-
devIndicator: DevIndicatorServerState
60+
devIndicator: DevToolsServerState['devIndicator']
6161
}
6262
interface BuiltAction {
6363
action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT
@@ -121,7 +121,7 @@ export interface AppIsrManifestAction {
121121

122122
export interface DevIndicatorAction {
123123
action: HMR_ACTIONS_SENT_TO_BROWSER.DEV_INDICATOR
124-
devIndicator: DevIndicatorServerState
124+
devIndicator: DevToolsServerState
125125
}
126126

127127
export type HMR_ACTION_TYPES =

0 commit comments

Comments
 (0)