Unverified Commit 91922c44 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add serverError action to list of HMR events (#54964)

Adds `serverError` to the list of HMR actions, missed this in the earlier PRs as it wasn't using `hotReloader.send`.

Also ensures on-demand-entry-handler reuses the hotReloader.send method.
parent 986f648b
......@@ -17,7 +17,7 @@ export function pageBootrap(assetPrefix: string) {
let buildIndicatorHandler: (obj: Record<string, any>) => void = () => {}
function devPagesHmrListener(payload: any) {
if (payload.action === 'serverError' && payload.errorJSON) {
if (payload.action === 'serverError') {
const { stack, message } = JSON.parse(payload.errorJSON)
const error = new Error(message)
error.stack = stack
......
......@@ -18,6 +18,12 @@ export const enum HMR_ACTIONS_SENT_TO_BROWSER {
PONG = 'pong',
DEV_PAGES_MANIFEST_UPDATE = 'devPagesManifestUpdate',
TURBOPACK_MESSAGE = 'turbopack-message',
SERVER_ERROR = 'serverError',
}
interface ServerErrorAction {
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR
errorJSON: string
}
interface TurboPackMessageAction {
......@@ -96,6 +102,7 @@ export type HMR_ACTION_TYPES =
| MiddlewareChangesAction
| ServerOnlyChangesAction
| DevPagesManifestUpdateAction
| ServerErrorAction
export interface NextJsHotReloaderInterface {
activeWebpackConfigs?: Array<Awaited<ReturnType<typeof getBaseWebpackConfig>>>
......
......@@ -1385,6 +1385,7 @@ export default class HotReloader implements NextJsHotReloaderInterface {
})
this.onDemandEntries = onDemandEntryHandler({
hotReloader: this,
multiCompiler: this.multiCompiler,
pagesDir: this.pagesDir,
appDir: this.appDir,
......
......@@ -35,6 +35,8 @@ import {
} from '../../shared/lib/constants'
import { RouteMatch } from '../future/route-matches/route-match'
import { isAppPageRouteMatch } from '../future/route-matches/app-page-route-match'
import { HMR_ACTIONS_SENT_TO_BROWSER } from './hot-reloader-types'
import HotReloader from './hot-reloader-webpack'
const debug = origDebug('next:on-demand-entry-handler')
......@@ -498,6 +500,7 @@ async function findRoutePathData(
}
export function onDemandEntryHandler({
hotReloader,
maxInactiveAge,
multiCompiler,
nextConfig,
......@@ -506,6 +509,7 @@ export function onDemandEntryHandler({
rootDir,
appDir,
}: {
hotReloader: HotReloader
maxInactiveAge: number
multiCompiler: webpack.MultiCompiler
nextConfig: NextConfigComplete
......@@ -947,12 +951,10 @@ export function onDemandEntryHandler({
// New error occurred: buffered error is flushed and new error occurred
if (!bufferedHmrServerError && error) {
client.send(
JSON.stringify({
action: 'serverError',
errorJSON: stringifyError(error),
})
)
hotReloader.send({
action: HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR,
errorJSON: stringifyError(error),
})
bufferedHmrServerError = null
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment