File tree 2 files changed +47
-3
lines changed
packages/runtime/src/templates/edge-shared
2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 1
1
import type { EdgeFunction } from 'https://edge.netlify.com'
2
2
3
+ // These are copied from next/dist/build. This file gets copied as part of the next
4
+ // runtime build and can't reference the next package directly.
5
+ //
6
+ // Latest types at https://github.com/vercel/next.js/blob/4a2df3c3752aeddc50fd5ab053440eccf71ae50b/packages/next/src/build/index.ts#L140
3
7
export declare type SsgRoute = {
4
8
initialRevalidateSeconds : number | false
5
9
srcRoute : string | null
6
- dataRoute : string
10
+ dataRoute : string | null
7
11
}
8
12
export declare type DynamicSsgRoute = {
9
13
routeRegex : string
10
14
fallback : string | null | false
11
- dataRoute : string
15
+ dataRoute : string | null
12
16
dataRouteRegex : string
13
17
}
14
18
export declare type PrerenderManifest = {
@@ -35,7 +39,7 @@ const rscifyPath = (route: string) => {
35
39
export const getRscDataRouter = ( { routes : staticRoutes , dynamicRoutes } : PrerenderManifest ) : EdgeFunction => {
36
40
const staticRouteSet = new Set (
37
41
Object . entries ( staticRoutes )
38
- . filter ( ( [ , { dataRoute } ] ) => dataRoute . endsWith ( '.rsc' ) )
42
+ . filter ( ( [ , { dataRoute } ] ) => dataRoute ? .endsWith ( '.rsc' ) )
39
43
. map ( ( [ route ] ) => route ) ,
40
44
)
41
45
Original file line number Diff line number Diff line change
1
+ import { getRscDataRouter , PrerenderManifest } from '../packages/runtime/src/templates/edge-shared/rsc-data'
2
+
3
+ const basePrerenderManifest : PrerenderManifest = {
4
+ version : 3 ,
5
+ routes : { } ,
6
+ dynamicRoutes : { } ,
7
+ notFoundRoutes : [ ] ,
8
+ }
9
+
10
+ describe ( 'getRscDataRouter' , ( ) => {
11
+ it ( 'should create a RSC data router when data routes are not present for routes' , ( ) => {
12
+ const manifest : PrerenderManifest = {
13
+ ...basePrerenderManifest ,
14
+ routes : {
15
+ '/' : {
16
+ initialRevalidateSeconds : 1 ,
17
+ srcRoute : null ,
18
+ dataRoute : '/index.json.rsc' ,
19
+ } ,
20
+ '/api/hello' : {
21
+ initialRevalidateSeconds : false ,
22
+ srcRoute : '/api/hello' ,
23
+ dataRoute : null ,
24
+ } ,
25
+ } ,
26
+ }
27
+
28
+ let rscDataRouter
29
+
30
+ // Normally type checking would pick this up, but because this file is copied when generating
31
+ // edge functions for the build, we need to make sure it's valid for builds.
32
+ //
33
+ // See https://github.com/netlify/next-runtime/issues/1940
34
+ expect ( ( ) => {
35
+ rscDataRouter = getRscDataRouter ( manifest )
36
+ } ) . not . toThrow ( )
37
+
38
+ expect ( typeof rscDataRouter ) . toBe ( 'function' )
39
+ } )
40
+ } )
You can’t perform that action at this time.
0 commit comments