@@ -5,14 +5,14 @@ import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
5
5
import { greenBright } from 'chalk'
6
6
import destr from 'destr'
7
7
import { copy , copyFile , emptyDir , ensureDir , readJSON , readJson , writeJSON , writeJson } from 'fs-extra'
8
- import type { PrerenderManifest , SsgRoute } from 'next/dist/build'
8
+ import type { PrerenderManifest } from 'next/dist/build'
9
9
import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middleware-plugin'
10
10
import type { RouteHas } from 'next/dist/lib/load-custom-routes'
11
11
import { outdent } from 'outdent'
12
12
13
13
import { getRequiredServerFiles , NextConfig } from './config'
14
14
import { makeLocaleOptional , stripLookahead } from './matchers'
15
- import { DynamicRoute , RoutesManifest } from './types'
15
+ import { RoutesManifest } from './types'
16
16
17
17
// This is the format as of next@12.2
18
18
interface EdgeFunctionDefinitionV1 {
@@ -70,14 +70,8 @@ const maybeLoadJson = <T>(path: string): Promise<T> | null => {
70
70
return readJson ( path )
71
71
}
72
72
}
73
-
74
- export const isStaticAppDirRoute = ( { srcRoute } : SsgRoute , manifest : Record < string , string > | null ) : boolean =>
75
- Boolean ( manifest ) && Object . values ( manifest ) . includes ( srcRoute )
76
-
77
- export const isDynamicAppDirRoute = (
78
- { page } : Pick < DynamicRoute , 'page' > ,
79
- manifest : Record < string , string > | null ,
80
- ) : boolean => Boolean ( manifest ) && Object . values ( manifest ) . includes ( page )
73
+ export const isAppDirRoute = ( route : string , appPathRoutesManifest : Record < string , string > | null ) : boolean =>
74
+ Boolean ( appPathRoutesManifest ) && Object . values ( appPathRoutesManifest ) . includes ( route )
81
75
82
76
export const loadMiddlewareManifest = ( netlifyConfig : NetlifyConfig ) : Promise < MiddlewareManifest | null > =>
83
77
maybeLoadJson ( resolve ( netlifyConfig . build . publish , 'server' , 'middleware-manifest.json' ) )
@@ -320,23 +314,38 @@ export const writeRscDataEdgeFunction = async ({
320
314
}
321
315
const staticAppdirRoutes : Array < string > = [ ]
322
316
for ( const [ path , route ] of Object . entries ( prerenderManifest . routes ) ) {
323
- if ( isStaticAppDirRoute ( route , appPathRoutesManifest ) ) {
317
+ if ( isAppDirRoute ( route . srcRoute , appPathRoutesManifest ) ) {
324
318
staticAppdirRoutes . push ( path , route . dataRoute )
325
319
}
326
320
}
327
- if ( staticAppdirRoutes . length === 0 ) {
321
+ const dynamicAppDirRoutes : Array < string > = [ ]
322
+
323
+ for ( const [ path , route ] of Object . entries ( prerenderManifest . dynamicRoutes ) ) {
324
+ if ( isAppDirRoute ( path , appPathRoutesManifest ) ) {
325
+ dynamicAppDirRoutes . push ( route . routeRegex , route . dataRouteRegex )
326
+ }
327
+ }
328
+
329
+ if ( staticAppdirRoutes . length === 0 && dynamicAppDirRoutes . length === 0 ) {
328
330
return [ ]
329
331
}
330
332
331
333
const edgeFunctionDir = resolve ( '.netlify' , 'edge-functions' , 'rsc-data' )
332
334
await ensureDir ( edgeFunctionDir )
333
335
await copyEdgeSourceFile ( { edgeFunctionDir, file : 'rsc-data.ts' } )
334
336
335
- return staticAppdirRoutes . map ( ( path ) => ( {
336
- function : 'rsc-data' ,
337
- name : 'RSC data routing' ,
338
- path,
339
- } ) )
337
+ return [
338
+ ...staticAppdirRoutes . map ( ( path ) => ( {
339
+ function : 'rsc-data' ,
340
+ name : 'RSC data routing' ,
341
+ path,
342
+ } ) ) ,
343
+ ...dynamicAppDirRoutes . map ( ( pattern ) => ( {
344
+ function : 'rsc-data' ,
345
+ name : 'RSC data routing' ,
346
+ pattern,
347
+ } ) ) ,
348
+ ]
340
349
}
341
350
342
351
/**
0 commit comments