Skip to content

Commit 659f684

Browse files
committed
fixup! handle the build time replacement of OPEN_NEXT_BUILD_ID
1 parent 4d610f4 commit 659f684

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

packages/cloudflare/src/api/durable-objects/queue.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class DOQueueHandler extends DurableObject<CloudflareEnv> {
165165
"INSERT OR REPLACE INTO sync (id, lastSuccess, buildId) VALUES (?, unixepoch(), ?)",
166166
// We cannot use the deduplication id because it's not unique per route - every time a route is revalidated, the deduplication id is different.
167167
`${host}${url}`,
168-
process.env.__NEXT_BUILD_ID
168+
process.env.__OPEN_NEXT_BUILD_ID
169169
);
170170
}
171171
// If everything went well, we can remove the route from the failed state
@@ -238,7 +238,7 @@ export class DOQueueHandler extends DurableObject<CloudflareEnv> {
238238
"INSERT OR REPLACE INTO failed_state (id, data, buildId) VALUES (?, ?, ?)",
239239
msg.MessageDeduplicationId,
240240
JSON.stringify(updatedFailedState),
241-
process.env.__NEXT_BUILD_ID
241+
process.env.__OPEN_NEXT_BUILD_ID
242242
);
243243
}
244244
// We probably want to do something if routeInFailedState is becoming too big, at least log it
@@ -273,8 +273,8 @@ export class DOQueueHandler extends DurableObject<CloudflareEnv> {
273273

274274
// Before doing anything else, we clear the DB for any potential old data
275275
// TODO: extract this to a function so that it could be called by the user at another time than init
276-
this.sql.exec("DELETE FROM failed_state WHERE buildId != ?", process.env.__NEXT_BUILD_ID);
277-
this.sql.exec("DELETE FROM sync WHERE buildId != ?", process.env.__NEXT_BUILD_ID);
276+
this.sql.exec("DELETE FROM failed_state WHERE buildId != ?", process.env.__OPEN_NEXT_BUILD_ID);
277+
this.sql.exec("DELETE FROM sync WHERE buildId != ?", process.env.__OPEN_NEXT_BUILD_ID);
278278

279279
const failedStateCursor = this.sql.exec<{ id: string; data: string }>("SELECT * FROM failed_state");
280280
for (const row of failedStateCursor) {

packages/cloudflare/src/cli/build/open-next/compileDurableObjects.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createRequire } from "node:module";
22
import path from "node:path";
33

4-
import { loadBuildId, loadPrerenderManifest } from "@opennextjs/aws/adapters/config/util.js";
4+
import { loadBuildId, loadConfig, loadPrerenderManifest } from "@opennextjs/aws/adapters/config/util.js";
55
import { type BuildOptions, esbuildSync } from "@opennextjs/aws/build/helper.js";
66

77
export function compileDurableObjects(buildOpts: BuildOptions) {
@@ -17,6 +17,7 @@ export function compileDurableObjects(buildOpts: BuildOptions) {
1717
const prerenderManifest = loadPrerenderManifest(buildOutputDotNextDir);
1818
const previewModeId = prerenderManifest?.preview?.previewModeId;
1919
const BUILD_ID = loadBuildId(buildOutputDotNextDir);
20+
const nextConfig = loadConfig(buildOutputDotNextDir);
2021

2122
return esbuildSync(
2223
{
@@ -28,7 +29,7 @@ export function compileDurableObjects(buildOpts: BuildOptions) {
2829
external: ["cloudflare:workers"],
2930
define: {
3031
"process.env.__NEXT_PREVIEW_MODE_ID": `"${previewModeId}"`,
31-
"process.env.__NEXT_BUILD_ID": `"${BUILD_ID}"`,
32+
"process.env.__OPEN_NEXT_BUILD_ID": JSON.stringify(nextConfig.deploymentId ?? BUILD_ID),
3233
},
3334
},
3435
buildOpts

0 commit comments

Comments
 (0)