Skip to content

Commit c7c5d3d

Browse files
authored
fix(tagCache): gracefully handle empty tag list (#581)
fixes #576
1 parent 68d6bb4 commit c7c5d3d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.changeset/cuddly-mails-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix(tagCache): gracefully handle empty tag list

packages/cloudflare/src/api/overrides/tag-cache/d1-next-tag-cache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { error } from "@opennextjs/aws/adapters/logger.js";
22
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";
33
import type { NextModeTagCache } from "@opennextjs/aws/types/overrides.js";
4-
import { RecoverableError } from "@opennextjs/aws/utils/error.js";
54

65
import { getCloudflareContext } from "../../cloudflare-context.js";
76
import { debugCache, FALLBACK_BUILD_ID } from "../internal.js";
@@ -36,15 +35,16 @@ export class D1NextModeTagCache implements NextModeTagCache {
3635

3736
async writeTags(tags: string[]): Promise<void> {
3837
const { isDisabled, db } = this.getConfig();
39-
if (isDisabled) return Promise.resolve();
40-
const result = await db.batch(
38+
// TODO: Remove `tags.length === 0` when https://github.com/opennextjs/opennextjs-aws/pull/828 is used
39+
if (isDisabled || tags.length === 0) return Promise.resolve();
40+
41+
await db.batch(
4142
tags.map((tag) =>
4243
db
4344
.prepare(`INSERT INTO revalidations (tag, revalidatedAt) VALUES (?, ?)`)
4445
.bind(this.getCacheKey(tag), Date.now())
4546
)
4647
);
47-
if (!result) throw new RecoverableError(`D1 insert failed for ${tags}`);
4848
}
4949

5050
private getConfig() {

0 commit comments

Comments
 (0)