Skip to content

Commit 1d1d1b7

Browse files
committed
review feedback
1 parent 1affdd1 commit 1d1d1b7

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

packages/next/src/server/dev/hot-reloader-turbopack.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
processTopLevelIssues,
6060
printNonFatalIssue,
6161
normalizedPageToTurbopackStructureRoute,
62+
type StartChangeSubscription,
6263
} from './turbopack-utils'
6364
import {
6465
propagateServerField,
@@ -1081,10 +1082,20 @@ export async function createHotReloaderTurbopack(
10811082
// trailing /page or /route segment (e.g. "/page" for the root route,
10821083
// "/blog/[slug]/page" for a dynamic page). Use normalizeAppPath to
10831084
// strip that suffix and find the entry matching the user-facing route.
1084-
let appOriginalName: string | undefined
1085+
let extraOptions: object | undefined = undefined
10851086
for (const [name] of currentEntrypoints.app) {
10861087
if (normalizeAppPath(name) === page) {
1087-
appOriginalName = name
1088+
extraOptions = {
1089+
// Synthesize a definition so ensurePage bypasses findPagePathData.
1090+
// Only page and bundlePath are used from the definition:
1091+
// - page: the originalName used as the route key for currentEntrypoints lookup
1092+
// - bundlePath: must start with "app/" to set isInsideAppDir=true
1093+
definition: {
1094+
page: name,
1095+
bundlePath: `app${name}`,
1096+
filename: '',
1097+
} as any,
1098+
}
10881099
break
10891100
}
10901101
}
@@ -1098,19 +1109,7 @@ export async function createHotReloaderTurbopack(
10981109
// updates for routes compiled this way, and these subscriptions
10991110
// are never unsubscribed (see TODOs in handleRouteType).
11001111
subscribeToChanges: false,
1101-
...(appOriginalName
1102-
? {
1103-
// Synthesize a definition so ensurePage bypasses findPagePathData.
1104-
// Only page and bundlePath are used from the definition:
1105-
// - page: the originalName used as the route key for currentEntrypoints lookup
1106-
// - bundlePath: must start with "app/" to set isInsideAppDir=true
1107-
definition: {
1108-
page: appOriginalName,
1109-
bundlePath: `app${appOriginalName}`,
1110-
filename: '',
1111-
} as any,
1112-
}
1113-
: {}),
1112+
...extraOptions,
11141113
}
11151114

11161115
// Snapshot the current issue maps before compilation so we can
@@ -1798,11 +1797,11 @@ export async function createHotReloaderTurbopack(
17981797
logErrors: true,
17991798

18001799
hooks: {
1801-
// Omit subscribeToChanges to skip wiring HMR subscriptions for
1800+
// Pass a no-o subscribeToChanges to skip wiring HMR subscriptions for
18021801
// one-shot compilations (e.g. compile_route MCP tool).
1803-
...(subscribeToChanges
1804-
? { subscribeToChanges: subscribeToClientChanges }
1805-
: null),
1802+
subscribeToChanges: subscribeToChanges
1803+
? subscribeToClientChanges
1804+
: ((async () => {}) as StartChangeSubscription),
18061805
handleWrittenEndpoint: (id, result, forceDeleteCache) => {
18071806
currentWrittenEntrypoints.set(id, result)
18081807
assetMapper.setPathsForKey(id, result.clientPaths)

packages/next/src/server/dev/turbopack-utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export type ClientStateMap = WeakMap<ws, ClientState>
140140
// is no client to receive updates and no unsubscribe path.
141141
type HandleRouteTypeHooks = {
142142
handleWrittenEndpoint: HandleWrittenEndpoint
143-
subscribeToChanges?: StartChangeSubscription
143+
subscribeToChanges: StartChangeSubscription
144144
}
145145

146146
export async function handleRouteType({
@@ -258,7 +258,7 @@ export async function handleRouteType({
258258
if (dev) {
259259
// TODO subscriptions should only be caused by the WebSocket connections
260260
// otherwise we don't known when to unsubscribe and this leaking
261-
hooks?.subscribeToChanges?.(
261+
hooks?.subscribeToChanges(
262262
serverKey,
263263
false,
264264
route.dataEndpoint,
@@ -277,7 +277,7 @@ export async function handleRouteType({
277277
}
278278
}
279279
)
280-
hooks?.subscribeToChanges?.(
280+
hooks?.subscribeToChanges(
281281
clientKey,
282282
false,
283283
route.htmlEndpoint,
@@ -294,7 +294,7 @@ export async function handleRouteType({
294294
}
295295
)
296296
if (entrypoints.global.document) {
297-
hooks?.subscribeToChanges?.(
297+
hooks?.subscribeToChanges(
298298
getEntryKey('pages', 'server', '_document'),
299299
false,
300300
entrypoints.global.document,
@@ -352,7 +352,7 @@ export async function handleRouteType({
352352
if (dev) {
353353
// TODO subscriptions should only be caused by the WebSocket connections
354354
// otherwise we don't known when to unsubscribe and this leaking
355-
hooks?.subscribeToChanges?.(
355+
hooks?.subscribeToChanges(
356356
key,
357357
true,
358358
route.rscEndpoint,
@@ -874,7 +874,7 @@ export async function handlePagesErrorRoute({
874874

875875
const writtenEndpoint = await entrypoints.global.app.writeToDisk()
876876
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
877-
hooks.subscribeToChanges?.(
877+
hooks.subscribeToChanges(
878878
key,
879879
false,
880880
entrypoints.global.app,
@@ -903,7 +903,7 @@ export async function handlePagesErrorRoute({
903903

904904
const writtenEndpoint = await entrypoints.global.document.writeToDisk()
905905
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
906-
hooks.subscribeToChanges?.(
906+
hooks.subscribeToChanges(
907907
key,
908908
false,
909909
entrypoints.global.document,
@@ -929,7 +929,7 @@ export async function handlePagesErrorRoute({
929929

930930
const writtenEndpoint = await entrypoints.global.error.writeToDisk()
931931
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
932-
hooks.subscribeToChanges?.(
932+
hooks.subscribeToChanges(
933933
key,
934934
false,
935935
entrypoints.global.error,

0 commit comments

Comments
 (0)