1
1
import { existsSync } from 'node:fs'
2
2
import { mkdir , readFile , writeFile } from 'node:fs/promises'
3
3
import { join } from 'node:path'
4
- import { join as posixJoin } from 'node:path/posix'
5
4
6
5
import { trace } from '@opentelemetry/api'
7
6
import { wrapTracer } from '@opentelemetry/api/experimental'
8
7
import { glob } from 'fast-glob'
9
8
import pLimit from 'p-limit'
10
9
import { satisfies } from 'semver'
11
10
12
- import { FS_BLOBS_MANIFEST } from '../../run/constants.js'
13
- import { type FSBlobsManifest } from '../../run/next.cjs'
14
11
import { encodeBlobKey } from '../../shared/blobkey.js'
15
12
import type {
16
13
CachedFetchValueForMultipleVersions ,
@@ -160,11 +157,6 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
160
157
} )
161
158
: false
162
159
163
- const fsBlobsManifest : FSBlobsManifest = {
164
- fallbackPaths : [ ] ,
165
- outputRoot : ctx . distDir ,
166
- }
167
-
168
160
await Promise . all ( [
169
161
...Object . entries ( manifest . routes ) . map (
170
162
( [ route , meta ] ) : Promise < void > =>
@@ -214,41 +206,15 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
214
206
await writeCacheEntry ( key , value , lastModified , ctx )
215
207
} ) ,
216
208
) ,
217
- ...Object . entries ( manifest . dynamicRoutes ) . map ( async ( [ route , meta ] ) => {
218
- // fallback can be `string | false | null`
219
- // - `string` - when user use pages router with `fallback: true`, and then it's html file path
220
- // - `null` - when user use pages router with `fallback: 'block'` or app router with `export const dynamicParams = true`
221
- // - `false` - when user use pages router with `fallback: false` or app router with `export const dynamicParams = false`
222
- if ( typeof meta . fallback === 'string' ) {
223
- // https://github.com/vercel/next.js/pull/68603 started using route cache to serve fallbacks
224
- // so we have to seed blobs with fallback entries
225
-
226
- // create cache entry for pages router with `fallback: true` case
227
- await limitConcurrentPrerenderContentHandling ( async ( ) => {
228
- // dynamic routes don't have entries for each locale so we have to generate them
229
- // ourselves. If i18n is not used we use empty string as "locale" to be able to use
230
- // same handling wether i18n is used or not
231
- const locales = ctx . buildConfig . i18n ?. locales ?? [ '' ]
209
+ ...ctx . getFallbacks ( manifest ) . map ( async ( route ) => {
210
+ const key = routeToFilePath ( route )
211
+ const value = await buildPagesCacheValue (
212
+ join ( ctx . publishDir , 'server/pages' , key ) ,
213
+ shouldUseEnumKind ,
214
+ true , // there is no corresponding json file for fallback, so we are skipping it for this entry
215
+ )
232
216
233
- const lastModified = Date . now ( )
234
- for ( const locale of locales ) {
235
- const key = routeToFilePath ( posixJoin ( locale , route ) )
236
- const value = await buildPagesCacheValue (
237
- join ( ctx . publishDir , 'server/pages' , key ) ,
238
- shouldUseEnumKind ,
239
- true , // there is no corresponding json file for fallback, so we are skipping it for this entry
240
- )
241
- // Netlify Forms are not support and require a workaround
242
- if ( value . kind === 'PAGE' || value . kind === 'PAGES' || value . kind === 'APP_PAGE' ) {
243
- verifyNetlifyForms ( ctx , value . html )
244
- }
245
-
246
- await writeCacheEntry ( key , value , lastModified , ctx )
247
-
248
- fsBlobsManifest . fallbackPaths . push ( `${ key } .html` )
249
- }
250
- } )
251
- }
217
+ await writeCacheEntry ( key , value , Date . now ( ) , ctx )
252
218
} ) ,
253
219
] )
254
220
@@ -263,10 +229,6 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
263
229
)
264
230
await writeCacheEntry ( key , value , lastModified , ctx )
265
231
}
266
- await writeFile (
267
- join ( ctx . serverHandlerDir , FS_BLOBS_MANIFEST ) ,
268
- JSON . stringify ( fsBlobsManifest ) ,
269
- )
270
232
} catch ( error ) {
271
233
ctx . failBuild ( 'Failed assembling prerendered content for upload' , error )
272
234
}
0 commit comments