Skip to content

Commit c20662e

Browse files
committed
fix: Execute HMR reload only when basePath it's the same as request handler
1 parent e02fe31 commit c20662e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/next/src/server/lib/router-server.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,20 @@ export async function initialize(opts: {
583583
})
584584

585585
if (opts.dev && developmentBundler && req.url) {
586-
const isHMRRequest = req.url.includes('/_next/webpack-hmr')
586+
const { basePath } = config
587+
588+
const isHMRRequestForHostApp =
589+
!basePath && req.url.startsWith('/_next/webpack-hmr')
590+
591+
const isHMRRequestForGuestApp =
592+
basePath && pathHasPrefix(req.url, basePath)
593+
594+
const isHMRRequestForCurrentBasepath =
595+
isHMRRequestForHostApp || isHMRRequestForGuestApp
596+
587597
// only handle HMR requests if the basePath in the request
588598
// matches the basePath for the handler responding to the request
589-
const isRequestForCurrentBasepath =
590-
!config.basePath || pathHasPrefix(req.url, config.basePath)
591-
592-
if (isHMRRequest && isRequestForCurrentBasepath) {
599+
if (isHMRRequestForCurrentBasepath) {
593600
return developmentBundler.hotReloader.onHMR(req, socket, head)
594601
}
595602
}

0 commit comments

Comments
 (0)