Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/e2e/pages-router/e2e/revalidate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from "@playwright/test";

test("`res.revalidate` should revalidate the ssg page", async ({ page, request }) => {
await page.goto("/ssg/");
const initialTime = await page.getByTestId("time").textContent();

await page.reload();
const newTime = await page.getByTestId("time").textContent();

expect(initialTime).toBe(newTime);

const revalidateResult = await request.post("/api/revalidate");
expect(revalidateResult.status()).toBe(200);
expect(await revalidateResult.json()).toEqual({ hello: "OpenNext rocks!" });

await page.reload();
const revalidatedTime = await page.getByTestId("time").textContent();
expect(initialTime).not.toBe(revalidatedTime);
});
11 changes: 11 additions & 0 deletions examples/e2e/pages-router/src/pages/api/revalidate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { NextApiRequest, NextApiResponse } from "next";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await res.revalidate("/ssg/");
return res.json({ hello: "OpenNext rocks!" });
} catch (e) {
console.error(e);
return res.status(500).json({ error: "An error occurred" });
}
}
21 changes: 21 additions & 0 deletions examples/e2e/pages-router/src/pages/ssg/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { InferGetStaticPropsType } from "next";
import Link from "next/link";

export async function getStaticProps() {
return {
props: {
time: new Date().toISOString(),
},
};
}

export default function Page({ time }: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<div>
<div className="flex" data-testid="time">
Time: {time}
</div>
<Link href="/">Home</Link>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type { FunctionOptions, SplittedFunctionOptions } from "@opennextjs/aws/t
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
import type { Plugin } from "esbuild";

import { patchResRevalidate } from "../patches/plugins/res-revalidate.js";
import { normalizePath } from "../utils/index.js";

interface CodeCustomization {
Expand Down Expand Up @@ -186,6 +187,8 @@ async function generateBundle(
patchFetchCacheSetMissingWaitUntil,
patchFetchCacheForISR,
patchUnstableCacheForISR,
// Cloudflare specific patches
patchResRevalidate,
...additionalCodePatches,
]);

Expand Down
Loading