Skip to content
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

Add turbopack-connected HMR event #54976

Merged
merged 1 commit into from
Sep 4, 2023
Merged
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
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