Skip to content

Commit

Permalink
Add turbopack-connected HMR event (vercel#54976)
Browse files Browse the repository at this point in the history
Additional HMR actions that weren't using the types yet.
  • Loading branch information
timneutkens authored Sep 4, 2023
1 parent f313235 commit 37a6e21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/next/src/server/dev/hot-reloader-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -51,7 +52,7 @@ interface RemovedPageAction {
data: [page: string | null]
}

interface ReloadPageAction {
export interface ReloadPageAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE
}

Expand All @@ -77,6 +78,10 @@ interface DevPagesManifestUpdateAction {
]
}

export interface TurboPackConnectedAction {
type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED
}

export type HMR_ACTION_TYPES =
| TurboPackMessageAction
| BuildingAction
Expand Down
12 changes: 10 additions & 2 deletions packages/next/src/server/lib/router-utils/setup-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
})
},

Expand Down

0 comments on commit 37a6e21

Please sign in to comment.