11import { existsSync } from 'node:fs'
22import { mkdir , readFile , writeFile } from 'node:fs/promises'
33import { join } from 'node:path'
4- import { join as posixJoin } from 'node:path/posix'
54
65import { trace } from '@opentelemetry/api'
76import { wrapTracer } from '@opentelemetry/api/experimental'
87import { glob } from 'fast-glob'
98import pLimit from 'p-limit'
109import { satisfies } from 'semver'
1110
12- import { FS_BLOBS_MANIFEST } from '../../run/constants.js'
13- import { type FSBlobsManifest } from '../../run/next.cjs'
1411import { encodeBlobKey } from '../../shared/blobkey.js'
1512import type {
1613 CachedFetchValueForMultipleVersions ,
@@ -160,11 +157,6 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
160157 } )
161158 : false
162159
163- const fsBlobsManifest : FSBlobsManifest = {
164- fallbackPaths : [ ] ,
165- outputRoot : ctx . distDir ,
166- }
167-
168160 await Promise . all ( [
169161 ...Object . entries ( manifest . routes ) . map (
170162 ( [ route , meta ] ) : Promise < void > =>
@@ -214,41 +206,15 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
214206 await writeCacheEntry ( key , value , lastModified , ctx )
215207 } ) ,
216208 ) ,
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+ )
232216
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 )
252218 } ) ,
253219 ] )
254220
@@ -263,10 +229,6 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
263229 )
264230 await writeCacheEntry ( key , value , lastModified , ctx )
265231 }
266- await writeFile (
267- join ( ctx . serverHandlerDir , FS_BLOBS_MANIFEST ) ,
268- JSON . stringify ( fsBlobsManifest ) ,
269- )
270232 } catch ( error ) {
271233 ctx . failBuild ( 'Failed assembling prerendered content for upload' , error )
272234 }
0 commit comments