Skip to content

Commit acfc7f3

Browse files
authored
D1 next mode tag cache (#464)
* Simple D1 next mode tag cache * add e2e tests * don't crash on get * changeset * review * fix broken lockfile
1 parent 60171f5 commit acfc7f3

23 files changed

+479
-16
lines changed

.changeset/ten-mice-clean.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+
Implement next mode for d1 tag cache that will reduce write

examples/common/apps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const apps = [
1212
"app-pages-router",
1313
"app-router",
1414
"pages-router",
15+
// overrides
16+
"d1-tag-next",
1517
// bugs
1618
"gh-119",
1719
"gh-219",

examples/common/config-e2e.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function configurePlaywright(
1313
isWorker = true,
1414
// Tests with multiple browsers
1515
multipleBrowsers = false,
16+
// Whether to run tests in single file in parallel
17+
parallel = true,
1618
} = {}
1719
) {
1820
const port = getAppPort(app, { isWorker });
@@ -60,7 +62,7 @@ export function configurePlaywright(
6062
/* ignore runtime specific tests */
6163
testIgnore: isWorker ? "*next.spec.ts" : "*cloudflare.spec.ts",
6264
/* Run tests in files in parallel */
63-
fullyParallel: true,
65+
fullyParallel: parallel,
6466
/* Fail the build on CI if you accidentally left test.only in the source code. */
6567
forbidOnly: isCI,
6668
/* Retry on CI only */
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts
42+
43+
# playwright
44+
/test-results/
45+
/playwright-report/
46+
/blob-report/
47+
/playwright/.cache/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use server";
2+
3+
import { revalidatePath, revalidateTag } from "next/cache";
4+
5+
export async function revalidateTagAction() {
6+
revalidateTag("date");
7+
}
8+
9+
export async function revalidatePathAction() {
10+
revalidatePath("/");
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use client";
2+
3+
import { revalidateTagAction, revalidatePathAction } from "../action";
4+
5+
export default function RevalidationButtons() {
6+
return (
7+
<div>
8+
<button
9+
data-testid="revalidate-tag"
10+
onClick={async () => {
11+
await revalidateTagAction();
12+
}}
13+
>
14+
Invalidate tag
15+
</button>
16+
17+
<button
18+
data-testid="revalidate-path"
19+
onClick={async () => {
20+
await revalidatePathAction();
21+
}}
22+
>
23+
Invalidate Path
24+
</button>
25+
</div>
26+
);
27+
}
25.3 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
html,
2+
body {
3+
max-width: 100vw;
4+
overflow-x: hidden;
5+
height: 100vh;
6+
display: flex;
7+
flex-direction: column;
8+
}
9+
10+
footer {
11+
padding: 1rem;
12+
display: flex;
13+
justify-content: end;
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { Metadata } from "next";
2+
import "./globals.css";
3+
4+
import { getCloudflareContext } from "@opennextjs/cloudflare";
5+
6+
export const metadata: Metadata = {
7+
title: "SSG App",
8+
description: "An app in which all the routes are SSG'd",
9+
};
10+
11+
export default async function RootLayout({
12+
children,
13+
}: Readonly<{
14+
children: React.ReactNode;
15+
}>) {
16+
const cloudflareContext = await getCloudflareContext({
17+
async: true,
18+
});
19+
20+
return (
21+
<html lang="en">
22+
<body>
23+
{children}
24+
<footer data-testid="app-version">{cloudflareContext.env.APP_VERSION}</footer>
25+
</body>
26+
</html>
27+
);
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.page {
2+
display: grid;
3+
grid-template-rows: 20px 1fr 20px;
4+
align-items: center;
5+
justify-items: center;
6+
flex: 1;
7+
border: 3px solid gray;
8+
margin: 1rem;
9+
margin-block-end: 0;
10+
}
11+
12+
.main {
13+
display: flex;
14+
flex-direction: column;
15+
gap: 32px;
16+
grid-row-start: 2;
17+
}

0 commit comments

Comments
 (0)