Skip to content

Commit 1e21fe9

Browse files
committed
Create unique source URLs between Client and Server in Pages dir
1 parent d0ad09c commit 1e21fe9

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

packages/next/src/build/entries.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,9 @@ export function finalizeEntrypoint({
869869
? WEBPACK_LAYERS.instrument
870870
: isServerComponent
871871
? WEBPACK_LAYERS.reactServerComponents
872-
: undefined
872+
: name.startsWith('pages/')
873+
? WEBPACK_LAYERS.pagesDirEdge
874+
: undefined
873875

874876
return {
875877
publicPath: isApi ? '' : undefined,
@@ -884,7 +886,9 @@ export function finalizeEntrypoint({
884886
? WEBPACK_LAYERS.api
885887
: isMiddlewareFilename(name) || isInstrumentation
886888
? WEBPACK_LAYERS.middleware
887-
: undefined,
889+
: name.startsWith('pages/')
890+
? WEBPACK_LAYERS.pagesDirEdge
891+
: undefined,
888892
library: { name: ['_ENTRIES', `middleware_[name]`], type: 'assign' },
889893
runtime: EDGE_RUNTIME_WEBPACK,
890894
asyncChunks: false,
@@ -919,6 +923,7 @@ export function finalizeEntrypoint({
919923
name.startsWith('pages/') && name !== 'pages/_app'
920924
? 'pages/_app'
921925
: CLIENT_STATIC_FILES_RUNTIME_MAIN,
926+
layer: WEBPACK_LAYERS.pagesDirBrowser,
922927
...entry,
923928
}
924929
}
@@ -930,7 +935,10 @@ export function finalizeEntrypoint({
930935
}
931936
}
932937

933-
return entry
938+
return {
939+
layer: WEBPACK_LAYERS.pagesDirBrowser,
940+
...entry,
941+
}
934942
}
935943
default: {
936944
// Should never happen.

packages/next/src/build/swc/generated-native.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ export class ExternalObject<T> {
3333
[K: symbol]: T
3434
}
3535
}
36-
export interface TransformOutput {
37-
code: string
38-
map?: string
39-
output?: string
40-
}
4136
export declare function mdxCompile(
4237
value: string,
4338
option: Buffer,

packages/next/src/build/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,13 @@ export function isWebpackClientOnlyLayer(
17821782
export function isWebpackDefaultLayer(
17831783
layer: WebpackLayerName | null | undefined
17841784
): boolean {
1785-
return layer === null || layer === undefined
1785+
return (
1786+
layer === null ||
1787+
layer === undefined ||
1788+
layer === WEBPACK_LAYERS.pagesDirBrowser ||
1789+
layer === WEBPACK_LAYERS.pagesDirEdge ||
1790+
layer === WEBPACK_LAYERS.pagesDirNode
1791+
)
17861792
}
17871793

17881794
export function isWebpackBundledLayer(

packages/next/src/lib/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ const WEBPACK_LAYERS_NAMES = {
137137
* The browser client bundle layer for App directory.
138138
*/
139139
appPagesBrowser: 'app-pages-browser',
140+
/**
141+
* The browser client bundle layer for Pages directory.
142+
*/
143+
pagesDirBrowser: 'pages-dir-browser',
144+
/**
145+
* The Edge Lite bundle layer for Pages directory.
146+
*/
147+
pagesDirEdge: 'pages-dir-edge',
148+
/**
149+
* The Node.js bundle layer for Pages directory.
150+
*/
151+
pagesDirNode: 'pages-dir-node',
140152
} as const
141153

142154
export type WebpackLayerName =

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,8 @@ export default class HotReloaderWebpack implements NextJsHotReloaderInterface {
522522
stackTrace
523523
)?.[1]
524524
if (file) {
525-
// `file` is filepath in `pages/` but it can be weird long webpack url in `app/`.
526-
// If it's a webpack loader URL, it will start with '(app-pages)/./'
525+
// `file` is filepath in `pages/` but it can be a webpack url.
526+
// If it's a webpack loader URL, it will include the app-pages layer
527527
if (
528528
file.startsWith(`(${WEBPACK_LAYERS.appPagesBrowser})/./`)
529529
) {
@@ -539,6 +539,15 @@ export default class HotReloaderWebpack implements NextJsHotReloaderInterface {
539539
if (modules.length > 0) {
540540
fileMessage = ` when ${modules.join(', ')} changed`
541541
}
542+
} else if (
543+
// Handle known webpack layers
544+
file.startsWith(`(${WEBPACK_LAYERS.pagesDirBrowser})/./`)
545+
) {
546+
const cleanedFilePath = file.slice(
547+
`(${WEBPACK_LAYERS.pagesDirBrowser})/`.length
548+
)
549+
550+
fileMessage = ` when ${cleanedFilePath} changed`
542551
} else {
543552
fileMessage = ` when ${file} changed`
544553
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function Root({ children }) {
2-
return children
2+
return <p>hello world</p>
33
}

0 commit comments

Comments
 (0)