Skip to content

Commit 7c1673b

Browse files
authored
fix: routes with null data routes can be filtered now (#2018)
* fix: routes with null data routes can be filtered now * chore: updated types * test: added test for RSC data router * test: added test for RSC data router * chore: added a comment about why I have a test that type checking would cover * chore: made a comment more comprehensive * test: skipping vary header test for rsc for now until issue is fixed
1 parent 40c308f commit 7c1673b

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

packages/runtime/src/templates/edge-shared/rsc-data.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import type { EdgeFunction } from 'https://edge.netlify.com'
22

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
37
export declare type SsgRoute = {
48
initialRevalidateSeconds: number | false
59
srcRoute: string | null
6-
dataRoute: string
10+
dataRoute: string | null
711
}
812
export declare type DynamicSsgRoute = {
913
routeRegex: string
1014
fallback: string | null | false
11-
dataRoute: string
15+
dataRoute: string | null
1216
dataRouteRegex: string
1317
}
1418
export declare type PrerenderManifest = {
@@ -35,7 +39,7 @@ const rscifyPath = (route: string) => {
3539
export const getRscDataRouter = ({ routes: staticRoutes, dynamicRoutes }: PrerenderManifest): EdgeFunction => {
3640
const staticRouteSet = new Set(
3741
Object.entries(staticRoutes)
38-
.filter(([, { dataRoute }]) => dataRoute.endsWith('.rsc'))
42+
.filter(([, { dataRoute }]) => dataRoute?.endsWith('.rsc'))
3943
.map(([route]) => route),
4044
)
4145

test/rsc-data.spec.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
})

0 commit comments

Comments
 (0)