File tree Expand file tree Collapse file tree 9 files changed +25
-21
lines changed Expand file tree Collapse file tree 9 files changed +25
-21
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/aws " : patch
3+ ---
4+
5+ Make ` NEXT_BUILD_ID ` and ` NEXT_PREVIEW_MODE_ID ` always available on ` process.env `
Original file line number Diff line number Diff line change @@ -40,3 +40,6 @@ export const AppPathRoutesManifest =
4040
4141export const FunctionsConfigManifest =
4242 /* @__PURE__ */ loadFunctionsConfigManifest ( NEXT_DIR ) ;
43+
44+ process . env . NEXT_BUILD_ID = BuildId ;
45+ process . env . NEXT_PREVIEW_MODE_ID = PrerenderManifest ?. preview ?. previewModeId ;
Original file line number Diff line number Diff line change @@ -76,10 +76,15 @@ export function loadConfigHeaders(nextDir: string) {
7676 return routesManifest . headers ;
7777}
7878
79- export function loadPrerenderManifest ( nextDir : string ) {
79+ export function loadPrerenderManifest (
80+ nextDir : string ,
81+ ) : PrerenderManifest | undefined {
8082 const filePath = path . join ( nextDir , "prerender-manifest.json" ) ;
83+ if ( ! fs . existsSync ( filePath ) ) {
84+ return undefined ;
85+ }
8186 const json = fs . readFileSync ( filePath , "utf-8" ) ;
82- return JSON . parse ( json ) as PrerenderManifest ;
87+ return JSON . parse ( json ) ;
8388}
8489
8590export function loadAppPathsManifest ( nextDir : string ) {
Original file line number Diff line number Diff line change 1- // We load every config here so that they are only loaded once
2- // and during cold starts
3- import { BuildId } from "config/index.js" ;
4-
51import { createMainHandler } from "../core/createMainHandler.js" ;
62import { setNodeEnv } from "./util.js" ;
73
84// We load every config here so that they are only loaded once
95// and during cold starts
106setNodeEnv ( ) ;
11- setBuildIdEnv ( ) ;
127setNextjsServerWorkingDirectory ( ) ;
138
149// Because next is messing with fetch, we have to make sure that we use an untouched version of fetch
@@ -29,9 +24,3 @@ function setNextjsServerWorkingDirectory() {
2924 // See https://opennext.js.org/aws/v2/advanced/workaround#workaround-set-nextserver-working-directory-aws-specific
3025 process . chdir ( __dirname ) ;
3126}
32-
33- function setBuildIdEnv ( ) {
34- // This allows users to access the CloudFront invalidating path when doing on-demand
35- // invalidations. ie. `/_next/data/${process.env.NEXT_BUILD_ID}/foo.json`
36- process . env . NEXT_BUILD_ID = BuildId ;
37- }
Original file line number Diff line number Diff line change @@ -362,7 +362,7 @@ File ${serverPath} does not exist
362362 const staticFiles : Array < string > = Object . values ( pagesManifest ) ;
363363 // Then we need to get all fallback: true dynamic routes html
364364 const locales = config . i18n ?. locales ;
365- Object . values ( prerenderManifest . dynamicRoutes ) . forEach ( ( route ) => {
365+ Object . values ( prerenderManifest ? .dynamicRoutes ?? { } ) . forEach ( ( route ) => {
366366 if ( typeof route . fallback === "string" ) {
367367 if ( locales ) {
368368 locales . forEach ( ( locale ) => {
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ async function computeCacheControl(
4242) {
4343 let finalRevalidate = CACHE_ONE_YEAR ;
4444
45- const existingRoute = Object . entries ( PrerenderManifest . routes ) . find (
45+ const existingRoute = Object . entries ( PrerenderManifest ? .routes ?? { } ) . find (
4646 ( p ) => p [ 0 ] === path ,
4747 ) ?. [ 1 ] ;
4848 if ( revalidate === undefined && existingRoute ) {
@@ -259,8 +259,10 @@ export async function cacheInterceptor(
259259 debug ( "Checking cache for" , localizedPath , PrerenderManifest ) ;
260260
261261 const isISR =
262- Object . keys ( PrerenderManifest . routes ) . includes ( localizedPath ?? "/" ) ||
263- Object . values ( PrerenderManifest . dynamicRoutes ) . some ( ( dr ) =>
262+ Object . keys ( PrerenderManifest ?. routes ?? { } ) . includes (
263+ localizedPath ?? "/" ,
264+ ) ||
265+ Object . values ( PrerenderManifest ?. dynamicRoutes ?? { } ) . some ( ( dr ) =>
264266 new RegExp ( dr . routeRegex ) . test ( localizedPath ) ,
265267 ) ;
266268 debug ( "isISR" , isISR ) ;
Original file line number Diff line number Diff line change @@ -422,10 +422,10 @@ export function fixDataPage(
422422
423423export function handleFallbackFalse (
424424 internalEvent : InternalEvent ,
425- prerenderManifest : PrerenderManifest ,
425+ prerenderManifest ? : PrerenderManifest ,
426426) : { event : InternalEvent ; isISR : boolean } {
427427 const { rawPath } = internalEvent ;
428- const { dynamicRoutes, routes } = prerenderManifest ;
428+ const { dynamicRoutes = { } , routes = { } } = prerenderManifest ?? { } ;
429429 const prerenderedFallbackRoutes = Object . entries ( dynamicRoutes ) . filter (
430430 ( [ , { fallback } ] ) => fallback === false ,
431431 ) ;
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ export async function handleMiddleware(
6060 if (
6161 headers [ "x-isr" ] &&
6262 headers [ "x-prerender-revalidate" ] ===
63- PrerenderManifest . preview . previewModeId
63+ PrerenderManifest ? .preview ? .previewModeId
6464 )
6565 return internalEvent ;
6666
Original file line number Diff line number Diff line change @@ -194,8 +194,8 @@ ${contents}
194194 export const FunctionsConfigManifest = ${ JSON . stringify ( FunctionsConfigManifest ) } ;
195195 export const PagesManifest = ${ JSON . stringify ( PagesManifest ) } ;
196196
197-
198197 process.env.NEXT_BUILD_ID = BuildId;
198+ process.env.NEXT_PREVIEW_MODE_ID = PrerenderManifest?.preview?.previewModeId;
199199` ;
200200 return { contents } ;
201201 } ,
You can’t perform that action at this time.
0 commit comments