Skip to content

Commit 4aede25

Browse files
committed
review fix
1 parent d70d5c7 commit 4aede25

File tree

8 files changed

+21
-12
lines changed

8 files changed

+21
-12
lines changed

packages/open-next/src/adapters/config/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,6 @@ export function loadFunctionsConfigManifest(nextDir: string) {
135135
const json = fs.readFileSync(filePath, "utf-8");
136136
return JSON.parse(json) as FunctionsConfigManifest;
137137
} catch (e) {
138-
return;
138+
return { functions: {}, version: 1 };
139139
}
140140
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//TODO: Move all other manifest path here as well
2+
export const MIDDLEWARE_TRACE_FILE = "server/middleware.js.nft.json";

packages/open-next/src/build/copyTracedFiles.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import path from "node:path";
1515
import type { NextConfig, PrerenderManifest } from "types/next-types";
1616

1717
import logger from "../logger.js";
18+
import { MIDDLEWARE_TRACE_FILE } from "./constant.js";
1819

1920
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
2021

@@ -143,11 +144,11 @@ File ${fullFilePath} does not exist
143144
}
144145
};
145146

146-
if (existsSync(path.join(dotNextDir, "server/middleware.js.nft.json"))) {
147+
if (existsSync(path.join(dotNextDir, MIDDLEWARE_TRACE_FILE))) {
147148
// We still need to copy the nft.json file so that computeCopyFilesForPage doesn't throw
148149
copyFileSync(
149-
path.join(dotNextDir, "server/middleware.js.nft.json"),
150-
path.join(standaloneNextDir, "server/middleware.js.nft.json"),
150+
path.join(dotNextDir, MIDDLEWARE_TRACE_FILE),
151+
path.join(standaloneNextDir, MIDDLEWARE_TRACE_FILE),
151152
);
152153
computeCopyFilesForPage("middleware");
153154
}

packages/open-next/src/build/createMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function createMiddleware(
5151
const functionsConfigManifest = JSON.parse(
5252
await fsAsync
5353
.readFile(functionsConfigManifestPath, "utf8")
54-
.catch(() => '{"functions":{}}'),
54+
.catch(() => '{"functions":{}, "version": 1}'),
5555
) as FunctionsConfigManifest;
5656

5757
if (functionsConfigManifest?.functions["/_middleware"]) {

packages/open-next/src/build/middleware/buildNodeMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ export async function buildExternalNodeMiddleware(
101101
],
102102
banner: {
103103
js: [
104-
`globalThis.monorepoPackagePath = "${packagePath}";`,
104+
`globalThis.monorepoPackagePath = '${packagePath}';`,
105105
"import process from 'node:process';",
106106
"import { Buffer } from 'node:buffer';",
107-
"import {AsyncLocalStorage} from 'node:async_hooks';",
107+
"import { AsyncLocalStorage } from 'node:async_hooks';",
108108
"import { createRequire as topLevelCreateRequire } from 'module';",
109109
"const require = topLevelCreateRequire(import.meta.url);",
110110
"import bannerUrl from 'url';",

packages/open-next/src/core/edgeFunctionHandler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export default async function edgeFunctionHandler(
2828
},
2929
},
3030
});
31-
// TODO: use the global waitUntil
32-
await result.waitUntil;
31+
globalThis.__openNextAls
32+
.getStore()
33+
?.pendingPromiseRunner.add(result.waitUntil);
3334
const response = result.response;
3435
return response;
3536
}

packages/open-next/src/core/nodeMiddlewareHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default async function middlewareHandler(
3939
request: request,
4040
page: "middleware",
4141
});
42-
// Not sure if we should await it here or defer to the global als
4342
globalThis.__openNextAls
4443
.getStore()
4544
?.pendingPromiseRunner.add(result.waitUntil);

packages/open-next/src/utils/promise.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ export function runWithOpenNextRequestContext<T>(
122122
},
123123
async () => {
124124
provideNextAfterProvider();
125-
const result = await fn();
126-
await awaitAllDetachedPromise();
125+
let result: T;
126+
try {
127+
result = await fn();
128+
// We always await all detached promises before returning the result
129+
// However we don't want to catch errors here, we want to let the parent handle it
130+
} finally {
131+
await awaitAllDetachedPromise();
132+
}
127133
return result;
128134
},
129135
);

0 commit comments

Comments
 (0)