Skip to content

[dev-tools] refactor: dev-indicator server state to dev-tools server state #79543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { useUntrackedPathname } from '../../navigation-untracked'
import { getComponentStack, getOwnerStack } from '../../errors/stitched-error'
import { handleDevBuildIndicatorHmrEvents } from '../../../dev/dev-build-indicator/internal/handle-dev-build-indicator-hmr-events'
import type { GlobalErrorComponent } from '../../global-error'
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
import type { DevToolsServerState } from '../../../../server/dev/dev-tools-server-state'
import reportHmrLatency from '../utils/report-hmr-latency'
import { TurbopackHmr } from '../utils/turbopack-hot-reloader-common'
import { NEXT_HMR_REFRESH_HASH_COOKIE } from '../../app-router-headers'
Expand All @@ -56,7 +56,7 @@ export interface Dispatcher {
onBeforeRefresh(): void
onRefresh(): void
onStaticIndicator(status: boolean): void
onDevIndicator(devIndicator: DevIndicatorServerState): void
onDevIndicator(devIndicator: DevToolsServerState['devIndicator']): void
}

let mostRecentCompilationHash: any = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../shared'
import type { VersionInfo } from '../../../../server/dev/parse-version-info'
import { getComponentStack, getOwnerStack } from '../../errors/stitched-error'
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state'
import type { DevToolsServerState } from '../../../../server/dev/dev-tools-server-state'

let isRegistered = false

Expand Down Expand Up @@ -126,8 +126,10 @@ export function onStaticIndicator(isStatic: boolean) {
Bus.emit({ type: ACTION_STATIC_INDICATOR, staticIndicator: isStatic })
}

export function onDevIndicator(devIndicatorsState: DevIndicatorServerState) {
Bus.emit({ type: ACTION_DEV_INDICATOR, devIndicator: devIndicatorsState })
export function onDevIndicator(
devIndicator: DevToolsServerState['devIndicator']
) {
Bus.emit({ type: ACTION_DEV_INDICATOR, devIndicator })
}

export { getErrorByType } from '../utils/get-error-by-type'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { VersionInfo } from '../../../server/dev/parse-version-info'
import type { SupportedErrorEvent } from './ui/container/runtime-error/render-error'
import type { ComponentStackFrame } from './utils/parse-component-stack'
import type { DebugInfo } from './types'
import type { DevIndicatorServerState } from '../../../server/dev/dev-indicator-server-state'
import type { DevToolsServerState } from '../../../server/dev/dev-tools-server-state'
import type { HMR_ACTION_TYPES } from '../../../server/dev/hot-reloader-types'
import { getOwnerStack } from '../errors/stitched-error'

Expand Down Expand Up @@ -87,7 +87,7 @@ interface VersionInfoAction {

interface DevIndicatorAction {
type: typeof ACTION_DEV_INDICATOR
devIndicator: DevIndicatorServerState
devIndicator: DevToolsServerState['devIndicator']
}

export type BusEvent =
Expand Down
5 changes: 3 additions & 2 deletions packages/next/src/server/dev/dev-indicator-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ServerResponse, IncomingMessage } from 'http'
import { middlewareResponse } from '../../client/components/react-dev-overlay/server/middleware-response'
import * as Log from '../../build/output/log'
import { devIndicatorServerState } from './dev-indicator-server-state'
import { devToolsServerState } from './dev-tools-server-state'

const DISABLE_DEV_INDICATOR_PREFIX = '/__nextjs_disable_dev_indicator'

Expand All @@ -27,7 +27,8 @@ export function getDisableDevIndicatorMiddleware() {
return middlewareResponse.methodNotAllowed(res)
}

devIndicatorServerState.disabledUntil = Date.now() + COOLDOWN_TIME_MS
devToolsServerState.devIndicator.disabledUntil =
Date.now() + COOLDOWN_TIME_MS

return middlewareResponse.noContent(res)
} catch (err) {
Expand Down
5 changes: 0 additions & 5 deletions packages/next/src/server/dev/dev-indicator-server-state.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/next/src/server/dev/dev-tools-server-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type DevToolsServerState = typeof devToolsServerState

export const devToolsServerState = {
devIndicator: { disabledUntil: 0 },
}
8 changes: 4 additions & 4 deletions packages/next/src/server/dev/hot-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { isMiddlewareFilename } from '../../build/utils'
import type { VersionInfo } from './parse-version-info'
import type { HMR_ACTION_TYPES } from './hot-reloader-types'
import { HMR_ACTIONS_SENT_TO_BROWSER } from './hot-reloader-types'
import { devIndicatorServerState } from './dev-indicator-server-state'
import { devToolsServerState } from './dev-tools-server-state'

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

if (devIndicatorServerState.disabledUntil < Date.now()) {
devIndicatorServerState.disabledUntil = 0
if (devToolsServerState.devIndicator.disabledUntil < Date.now()) {
devToolsServerState.devIndicator.disabledUntil = 0
}

this.publish({
Expand All @@ -219,7 +219,7 @@ export class WebpackHotMiddleware {
debug: {
devtoolsFrontendUrl: this.devtoolsFrontendUrl,
},
devIndicator: devIndicatorServerState,
devIndicator: devToolsServerState.devIndicator,
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import {
type TopLevelIssuesMap,
} from '../../shared/lib/turbopack/utils'
import { getDevOverlayFontMiddleware } from '../../client/components/react-dev-overlay/font/get-dev-overlay-font-middleware'
import { devIndicatorServerState } from './dev-indicator-server-state'
import { devToolsServerState } from './dev-tools-server-state'
import { getDisableDevIndicatorMiddleware } from './dev-indicator-middleware'
import { getRestartDevServerMiddleware } from '../../client/components/react-dev-overlay/server/restart-dev-server-middleware'
// import { getSupportedBrowsers } from '../../build/utils'
Expand Down Expand Up @@ -839,8 +839,8 @@ export async function createHotReloaderTurbopack(
}
}

if (devIndicatorServerState.disabledUntil < Date.now()) {
devIndicatorServerState.disabledUntil = 0
if (devToolsServerState.devIndicator.disabledUntil < Date.now()) {
devToolsServerState.devIndicator.disabledUntil = 0
}

;(async function () {
Expand All @@ -855,7 +855,7 @@ export async function createHotReloaderTurbopack(
debug: {
devtoolsFrontendUrl,
},
devIndicator: devIndicatorServerState,
devIndicator: devToolsServerState.devIndicator,
}

sendToClient(client, sync)
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/server/dev/hot-reloader-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { RouteDefinition } from '../route-definitions/route-definition'
import type { Project, Update as TurbopackUpdate } from '../../build/swc/types'
import type { VersionInfo } from './parse-version-info'
import type { DebugInfo } from '../../client/components/react-dev-overlay/types'
import type { DevIndicatorServerState } from './dev-indicator-server-state'
import type { DevToolsServerState } from './dev-tools-server-state'

export const enum HMR_ACTIONS_SENT_TO_BROWSER {
ADDED_PAGE = 'addedPage',
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface SyncAction {
versionInfo: VersionInfo
updatedModules?: ReadonlyArray<string>
debug?: DebugInfo
devIndicator: DevIndicatorServerState
devIndicator: DevToolsServerState['devIndicator']
}
interface BuiltAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT
Expand Down Expand Up @@ -121,7 +121,7 @@ export interface AppIsrManifestAction {

export interface DevIndicatorAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.DEV_INDICATOR
devIndicator: DevIndicatorServerState
devIndicator: DevToolsServerState
}

export type HMR_ACTION_TYPES =
Expand Down
Loading