From 76999dbfe9b07bea05e4548de3e7767162cb776c Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 4 Sep 2023 15:32:52 +0200 Subject: [PATCH] Add turbopack-connected HMR event --- packages/next/src/server/dev/hot-reloader-types.ts | 7 ++++++- .../next/src/server/lib/router-utils/setup-dev.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/next/src/server/dev/hot-reloader-types.ts b/packages/next/src/server/dev/hot-reloader-types.ts index cdb3c26ab708a..cceb329231edc 100644 --- a/packages/next/src/server/dev/hot-reloader-types.ts +++ b/packages/next/src/server/dev/hot-reloader-types.ts @@ -18,6 +18,7 @@ export const enum HMR_ACTIONS_SENT_TO_BROWSER { DEV_PAGES_MANIFEST_UPDATE = 'devPagesManifestUpdate', TURBOPACK_MESSAGE = 'turbopack-message', SERVER_ERROR = 'serverError', + TURBOPACK_CONNECTED = 'turbopack-connected', } interface ServerErrorAction { @@ -51,7 +52,7 @@ interface RemovedPageAction { data: [page: string | null] } -interface ReloadPageAction { +export interface ReloadPageAction { action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE } @@ -77,6 +78,10 @@ interface DevPagesManifestUpdateAction { ] } +export interface TurboPackConnectedAction { + type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED +} + export type HMR_ACTION_TYPES = | TurboPackMessageAction | BuildingAction diff --git a/packages/next/src/server/lib/router-utils/setup-dev.ts b/packages/next/src/server/lib/router-utils/setup-dev.ts index a2cba295a7bab..00e23a4fe73e5 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev.ts @@ -100,6 +100,8 @@ import { HMR_ACTIONS_SENT_TO_BROWSER, HMR_ACTION_TYPES, NextJsHotReloaderInterface, + ReloadPageAction, + TurboPackConnectedAction, } from '../../dev/hot-reloader-types' import { debounce } from '../../utils' @@ -790,7 +792,10 @@ async function startWatcher(opts: SetupOpts) { // to fully reload the page to resolve the issue. We can't use // `hotReloader.send` since that would force very connected client to // reload, only this client is out of date. - client.send(JSON.stringify({ action: 'reloadPage' })) + const reloadAction: ReloadPageAction = { + action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE, + } + client.send(JSON.stringify(reloadAction)) client.close() return } @@ -910,7 +915,10 @@ async function startWatcher(opts: SetupOpts) { } }) - client.send(JSON.stringify({ type: 'turbopack-connected' })) + const turbopackConnected: TurboPackConnectedAction = { + type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED, + } + client.send(JSON.stringify(turbopackConnected)) }) },