Skip to content

Commit c21addb

Browse files
committed
review feedback
1 parent 097ada3 commit c21addb

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,
@@ -1088,10 +1089,20 @@ export async function createHotReloaderTurbopack(
10881089
// trailing /page or /route segment (e.g. "/page" for the root route,
10891090
// "/blog/[slug]/page" for a dynamic page). Use normalizeAppPath to
10901091
// strip that suffix and find the entry matching the user-facing route.
1091-
let appOriginalName: string | undefined
1092+
let extraOptions: object | undefined = undefined
10921093
for (const [name] of currentEntrypoints.app) {
10931094
if (normalizeAppPath(name) === page) {
1094-
appOriginalName = name
1095+
extraOptions = {
1096+
// Synthesize a definition so ensurePage bypasses findPagePathData.
1097+
// Only page and bundlePath are used from the definition:
1098+
// - page: the originalName used as the route key for currentEntrypoints lookup
1099+
// - bundlePath: must start with "app/" to set isInsideAppDir=true
1100+
definition: {
1101+
page: name,
1102+
bundlePath: `app${name}`,
1103+
filename: '',
1104+
} as any,
1105+
}
10951106
break
10961107
}
10971108
}
@@ -1105,19 +1116,7 @@ export async function createHotReloaderTurbopack(
11051116
// updates for routes compiled this way, and these subscriptions
11061117
// are never unsubscribed (see TODOs in handleRouteType).
11071118
subscribeToChanges: false,
1108-
...(appOriginalName
1109-
? {
1110-
// Synthesize a definition so ensurePage bypasses findPagePathData.
1111-
// Only page and bundlePath are used from the definition:
1112-
// - page: the originalName used as the route key for currentEntrypoints lookup
1113-
// - bundlePath: must start with "app/" to set isInsideAppDir=true
1114-
definition: {
1115-
page: appOriginalName,
1116-
bundlePath: `app${appOriginalName}`,
1117-
filename: '',
1118-
} as any,
1119-
}
1120-
: {}),
1119+
...extraOptions,
11211120
}
11221121

11231122
// Snapshot the current issue maps before compilation so we can
@@ -1805,11 +1804,11 @@ export async function createHotReloaderTurbopack(
18051804
logErrors: true,
18061805

18071806
hooks: {
1808-
// Omit subscribeToChanges to skip wiring HMR subscriptions for
1807+
// Pass a no-o subscribeToChanges to skip wiring HMR subscriptions for
18091808
// one-shot compilations (e.g. compile_route MCP tool).
1810-
...(subscribeToChanges
1811-
? { subscribeToChanges: subscribeToClientChanges }
1812-
: null),
1809+
subscribeToChanges: subscribeToChanges
1810+
? subscribeToClientChanges
1811+
: ((async () => {}) as StartChangeSubscription),
18131812
handleWrittenEndpoint: (id, result, forceDeleteCache) => {
18141813
currentWrittenEntrypoints.set(id, result)
18151814
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
@@ -139,7 +139,7 @@ export type ClientStateMap = WeakMap<ws, ClientState>
139139
// is no client to receive updates and no unsubscribe path.
140140
type HandleRouteTypeHooks = {
141141
handleWrittenEndpoint: HandleWrittenEndpoint
142-
subscribeToChanges?: StartChangeSubscription
142+
subscribeToChanges: StartChangeSubscription
143143
}
144144

145145
export async function handleRouteType({
@@ -256,7 +256,7 @@ export async function handleRouteType({
256256
if (dev) {
257257
// TODO subscriptions should only be caused by the WebSocket connections
258258
// otherwise we don't known when to unsubscribe and this leaking
259-
hooks?.subscribeToChanges?.(
259+
hooks?.subscribeToChanges(
260260
serverKey,
261261
false,
262262
route.dataEndpoint,
@@ -275,7 +275,7 @@ export async function handleRouteType({
275275
}
276276
}
277277
)
278-
hooks?.subscribeToChanges?.(
278+
hooks?.subscribeToChanges(
279279
clientKey,
280280
false,
281281
route.htmlEndpoint,
@@ -292,7 +292,7 @@ export async function handleRouteType({
292292
}
293293
)
294294
if (entrypoints.global.document) {
295-
hooks?.subscribeToChanges?.(
295+
hooks?.subscribeToChanges(
296296
getEntryKey('pages', 'server', '_document'),
297297
false,
298298
entrypoints.global.document,
@@ -349,7 +349,7 @@ export async function handleRouteType({
349349
if (dev) {
350350
// TODO subscriptions should only be caused by the WebSocket connections
351351
// otherwise we don't known when to unsubscribe and this leaking
352-
hooks?.subscribeToChanges?.(
352+
hooks?.subscribeToChanges(
353353
key,
354354
true,
355355
route.rscEndpoint,
@@ -869,7 +869,7 @@ export async function handlePagesErrorRoute({
869869

870870
const writtenEndpoint = await entrypoints.global.app.writeToDisk()
871871
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
872-
hooks.subscribeToChanges?.(
872+
hooks.subscribeToChanges(
873873
key,
874874
false,
875875
entrypoints.global.app,
@@ -898,7 +898,7 @@ export async function handlePagesErrorRoute({
898898

899899
const writtenEndpoint = await entrypoints.global.document.writeToDisk()
900900
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
901-
hooks.subscribeToChanges?.(
901+
hooks.subscribeToChanges(
902902
key,
903903
false,
904904
entrypoints.global.document,
@@ -924,7 +924,7 @@ export async function handlePagesErrorRoute({
924924

925925
const writtenEndpoint = await entrypoints.global.error.writeToDisk()
926926
hooks.handleWrittenEndpoint(key, writtenEndpoint, false)
927-
hooks.subscribeToChanges?.(
927+
hooks.subscribeToChanges(
928928
key,
929929
false,
930930
entrypoints.global.error,

0 commit comments

Comments
 (0)