@@ -48,10 +48,11 @@ const routeToFilePath = (path: string) => (path === '/' ? '/index' : path)
48
48
const buildPagesCacheValue = async (
49
49
path : string ,
50
50
shouldUseEnumKind : boolean ,
51
+ shouldSkipJson = false ,
51
52
) : Promise < NetlifyCachedPageValue > => ( {
52
53
kind : shouldUseEnumKind ? 'PAGES' : 'PAGE' ,
53
54
html : await readFile ( `${ path } .html` , 'utf-8' ) ,
54
- pageData : JSON . parse ( await readFile ( `${ path } .json` , 'utf-8' ) ) ,
55
+ pageData : shouldSkipJson ? { } : JSON . parse ( await readFile ( `${ path } .json` , 'utf-8' ) ) ,
55
56
headers : undefined ,
56
57
status : undefined ,
57
58
} )
@@ -146,8 +147,8 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
146
147
} )
147
148
: false
148
149
149
- await Promise . all (
150
- Object . entries ( manifest . routes ) . map (
150
+ await Promise . all ( [
151
+ ... Object . entries ( manifest . routes ) . map (
151
152
( [ route , meta ] ) : Promise < void > =>
152
153
limitConcurrentPrerenderContentHandling ( async ( ) => {
153
154
const lastModified = meta . initialRevalidateSeconds
@@ -195,7 +196,35 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
195
196
await writeCacheEntry ( key , value , lastModified , ctx )
196
197
} ) ,
197
198
) ,
198
- )
199
+ ...Object . entries ( manifest . dynamicRoutes ) . map ( async ( [ route , meta ] ) => {
200
+ // fallback can be `string | false | null`
201
+ // - `string` - when user use pages router with `fallback: true`, and then it's html file path
202
+ // - `null` - when user use pages router with `fallback: 'block'` or app router with `export const dynamicParams = true`
203
+ // - `false` - when user use pages router with `fallback: false` or app router with `export const dynamicParams = false`
204
+ if ( typeof meta . fallback === 'string' ) {
205
+ // https://github.com/vercel/next.js/pull/68603 started using route cache to serve fallbacks
206
+ // so we have to seed blobs with fallback entries
207
+
208
+ // create cache entry for pages router with `fallback: true` case
209
+ await limitConcurrentPrerenderContentHandling ( async ( ) => {
210
+ const lastModified = Date . now ( )
211
+ const key = routeToFilePath ( route )
212
+
213
+ const value = await buildPagesCacheValue (
214
+ join ( ctx . publishDir , 'server/pages' , key ) ,
215
+ shouldUseEnumKind ,
216
+ true , // there is no corresponding json file for fallback, so we are skipping it for this entry
217
+ )
218
+ // Netlify Forms are not support and require a workaround
219
+ if ( value . kind === 'PAGE' || value . kind === 'PAGES' || value . kind === 'APP_PAGE' ) {
220
+ verifyNetlifyForms ( ctx , value . html )
221
+ }
222
+
223
+ await writeCacheEntry ( key , value , lastModified , ctx )
224
+ } )
225
+ }
226
+ } ) ,
227
+ ] )
199
228
200
229
// app router 404 pages are not in the prerender manifest
201
230
// so we need to check for them manually
0 commit comments