@@ -4,7 +4,7 @@ import type {
4
4
} from '../loaders/next-flight-client-entry-loader'
5
5
6
6
import { webpack } from 'next/dist/compiled/webpack/webpack'
7
- import { stringify } from 'querystring'
7
+ import { parse , stringify } from 'querystring'
8
8
import path from 'path'
9
9
import { sources } from 'next/dist/compiled/webpack/webpack'
10
10
import {
@@ -13,7 +13,10 @@ import {
13
13
EntryTypes ,
14
14
getEntryKey ,
15
15
} from '../../../server/dev/on-demand-entry-handler'
16
- import { WEBPACK_LAYERS } from '../../../lib/constants'
16
+ import {
17
+ WEBPACK_LAYERS ,
18
+ WEBPACK_RESOURCE_QUERIES ,
19
+ } from '../../../lib/constants'
17
20
import {
18
21
APP_CLIENT_INTERNALS ,
19
22
BARREL_OPTIMIZATION_PREFIX ,
@@ -41,6 +44,7 @@ import { PAGE_TYPES } from '../../../lib/page-types'
41
44
import { getModuleBuildInfo } from '../loaders/get-module-build-info'
42
45
import { getAssumedSourceType } from '../loaders/next-flight-loader'
43
46
import { isAppRouteRoute } from '../../../lib/is-app-route-route'
47
+ import { isMetadataRoute } from '../../../lib/metadata/is-metadata-route'
44
48
45
49
interface Options {
46
50
dev : boolean
@@ -296,10 +300,14 @@ export class FlightClientEntryPlugin {
296
300
compilation . moduleGraph
297
301
) ) {
298
302
// Entry can be any user defined entry files such as layout, page, error, loading, etc.
299
- const entryRequest = (
303
+ let entryRequest = (
300
304
connection . dependency as unknown as webpack . NormalModule
301
305
) . request
302
306
307
+ if ( entryRequest . endsWith ( WEBPACK_RESOURCE_QUERIES . metadataRoute ) ) {
308
+ entryRequest = getMetadataRouteResource ( entryRequest )
309
+ }
310
+
303
311
const { clientComponentImports, actionImports, cssImports } =
304
312
this . collectComponentInfoFromServerEntryDependency ( {
305
313
entryRequest,
@@ -332,10 +340,16 @@ export class FlightClientEntryPlugin {
332
340
: entryRequest
333
341
334
342
// Replace file suffix as `.js` will be added.
335
- const bundlePath = normalizePathSep (
343
+ let bundlePath = normalizePathSep (
336
344
relativeRequest . replace ( / \. [ ^ . \\ / ] + $ / , '' ) . replace ( / ^ s r c [ \\ / ] / , '' )
337
345
)
338
346
347
+ // For metadata routes, the entry name can be used as the bundle path,
348
+ // as it has been normalized already.
349
+ if ( isMetadataRoute ( bundlePath ) ) {
350
+ bundlePath = name
351
+ }
352
+
339
353
Object . assign ( mergedCSSimports , cssImports )
340
354
clientEntriesToInject . push ( {
341
355
compiler,
@@ -1094,5 +1108,16 @@ function getModuleResource(mod: webpack.NormalModule): string {
1094
1108
if ( mod . matchResource ?. startsWith ( BARREL_OPTIMIZATION_PREFIX ) ) {
1095
1109
modResource = mod . matchResource + ':' + modResource
1096
1110
}
1111
+
1112
+ if ( mod . resource === `?${ WEBPACK_RESOURCE_QUERIES . metadataRoute } ` ) {
1113
+ return getMetadataRouteResource ( mod . rawRequest )
1114
+ }
1115
+
1097
1116
return modResource
1098
1117
}
1118
+
1119
+ function getMetadataRouteResource ( request : string ) : string {
1120
+ const query = request . split ( 'next-metadata-route-loader?' ) [ 1 ]
1121
+
1122
+ return parse ( query ) . filePath as string
1123
+ }
0 commit comments