File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
packages/open-next/src/adapters Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " open-next " : patch
3+ ---
4+
5+ Fix incorrect 200 with wrong buildId for page router
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ export const processInternalEvent: ProcessInternalEvent = async (
4242 const nextHeaders = addNextConfigHeaders ( event , ConfigHeaders ) ?? { } ;
4343
4444 let internalEvent = fixDataPage ( event , BuildId ) ;
45+ // If we return InternalResult, it means that the build id is not correct
46+ // We should return a 404
47+ if ( "statusCode" in internalEvent ) {
48+ return internalEvent ;
49+ }
4550
4651 internalEvent = handleFallbackFalse ( internalEvent , PrerenderManifest ) ;
4752
Original file line number Diff line number Diff line change @@ -239,9 +239,24 @@ export function handleRedirects(
239239 }
240240}
241241
242- export function fixDataPage ( internalEvent : InternalEvent , buildId : string ) {
242+ export function fixDataPage (
243+ internalEvent : InternalEvent ,
244+ buildId : string ,
245+ ) : InternalEvent | InternalResult {
243246 const { rawPath, query } = internalEvent ;
244247 const dataPattern = `/_next/data/${ buildId } ` ;
248+ // Return 404 for data requests that don't match the buildId
249+ if ( rawPath . startsWith ( "/_next/data" ) && ! rawPath . startsWith ( dataPattern ) ) {
250+ return {
251+ type : internalEvent . type ,
252+ statusCode : 404 ,
253+ body : "{}" ,
254+ headers : {
255+ "Content-Type" : "application/json" ,
256+ } ,
257+ isBase64Encoded : false ,
258+ } ;
259+ }
245260
246261 if ( rawPath . startsWith ( dataPattern ) && rawPath . endsWith ( ".json" ) ) {
247262 let newPath = rawPath . replace ( dataPattern , "" ) . replace ( / \. j s o n $ / , "" ) ;
You can’t perform that action at this time.
0 commit comments