Fixes for Turbopack HMR (#54790)
### What? There were a few issues with the initial implementation of next-api HMR: 1. We incorrectly errored out when we received a Next.js WebSocket message 2. We didn't handle Next's `span-end` message, leading to another error 3. We listened to the `htmlEndpoint` change events instead of the `dataEndpoint`/`rscEndpoint`, leading to us detecting client-side changes and causing full page reloads ### Why? HMR is the life-blood of development ### How? Small fixes to our Turbopack reimplementation of the server-side HRM handlers Closes WEB-1475
This commit is contained in:
parent
7744aa2640
commit
8b4bb031ba
1 changed files with 7 additions and 3 deletions
|
@ -754,6 +754,7 @@ async function startWatcher(opts: SetupOpts) {
|
|||
case 'server-component-reload-page': // { clientId }
|
||||
case 'client-reload-page': // { clientId }
|
||||
case 'client-full-reload': // { stackTrace, hadRuntimeError }
|
||||
case 'span-end': // { startTime, endTime, spanName, attributes }
|
||||
// TODO
|
||||
break
|
||||
|
||||
|
@ -775,7 +776,10 @@ async function startWatcher(opts: SetupOpts) {
|
|||
break
|
||||
|
||||
default:
|
||||
throw new Error(`unrecognized Turbopack HMR message "${data}"`)
|
||||
// Might have been a Next.js message...
|
||||
if (!parsedData.event) {
|
||||
throw new Error(`unrecognized Turbopack message "${data}"`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -886,7 +890,7 @@ async function startWatcher(opts: SetupOpts) {
|
|||
page,
|
||||
await route.htmlEndpoint.writeToDisk()
|
||||
)
|
||||
changeSubscription(page, route.htmlEndpoint, (pageName, change) => {
|
||||
changeSubscription(page, route.dataEndpoint, (pageName, change) => {
|
||||
switch (change) {
|
||||
case ServerClientChangeType.Server:
|
||||
case ServerClientChangeType.Both:
|
||||
|
@ -939,7 +943,7 @@ async function startWatcher(opts: SetupOpts) {
|
|||
}
|
||||
case 'app-page': {
|
||||
await processResult(page, await route.htmlEndpoint.writeToDisk())
|
||||
changeSubscription(page, route.htmlEndpoint, (_page, change) => {
|
||||
changeSubscription(page, route.rscEndpoint, (_page, change) => {
|
||||
switch (change) {
|
||||
case ServerClientChangeType.Server:
|
||||
case ServerClientChangeType.Both:
|
||||
|
|
Loading…
Reference in a new issue