-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fetchCache for next 14+ * fix: regression from #295, tags were not generated * test: add test for revalidateTag * pin next version * add changeset
- Loading branch information
Showing
13 changed files
with
192 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"open-next": patch | ||
--- | ||
|
||
Setting the right tag values for fetch cache (#304); Fix getHeader crash external rewrites (#321); Added --package-json option to specify package json path (#322); Change querystring format for multi value parameters (#320);Fix tags cache (#317);Fix skip trailing slash redirect (#323) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { revalidateTag } from "next/cache"; | ||
|
||
export async function GET() { | ||
revalidateTag("revalidate"); | ||
|
||
return new Response("ok"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { unstable_cache } from "next/cache"; | ||
import type { ReactNode } from "react"; | ||
|
||
export default async function Layout({ children }: { children: ReactNode }) { | ||
const fakeFetch = unstable_cache( | ||
async () => new Date().getTime(), | ||
["fakeFetch"], | ||
{ | ||
tags: ["revalidate"], | ||
}, | ||
); | ||
const fetchedDate = await fakeFetch(); | ||
return ( | ||
<div> | ||
<div>Fetched time: {new Date(fetchedDate).toISOString()}</div> | ||
{children} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function Nested() { | ||
return <div>Nested</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
async function getTime() { | ||
return new Date().toISOString(); | ||
} | ||
|
||
export default async function ISR() { | ||
const time = getTime(); | ||
return <div>Time: {time}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test("Revalidate tag", async ({ page, request }) => { | ||
test.setTimeout(45000); | ||
let responsePromise = page.waitForResponse((response) => { | ||
return response.status() === 200; | ||
}); | ||
await page.goto("/revalidate-tag"); | ||
let elLayout = page.getByText("Fetched time:"); | ||
let time = await elLayout.textContent(); | ||
let newTime; | ||
|
||
let response = await responsePromise; | ||
const nextCacheHeader = response.headers()["x-nextjs-cache"]; | ||
expect(nextCacheHeader).toMatch(/^(HIT|STALE)$/); | ||
|
||
// Send revalidate tag request | ||
|
||
const result = await request.get("/api/revalidate-tag"); | ||
expect(result.status()).toEqual(200); | ||
const text = await result.text(); | ||
expect(text).toEqual("ok"); | ||
|
||
responsePromise = page.waitForResponse((response) => { | ||
return response.status() === 200; | ||
}); | ||
await page.reload(); | ||
elLayout = page.getByText("Fetched time:"); | ||
newTime = await elLayout.textContent(); | ||
|
||
expect(newTime).not.toEqual(time); | ||
|
||
response = await responsePromise; | ||
expect(response.headers()["x-nextjs-cache"]).toEqual("MISS"); | ||
|
||
//Check if nested page is also a miss | ||
responsePromise = page.waitForResponse((response) => { | ||
return response.status() === 200; | ||
}); | ||
await page.goto("/revalidate-tag/nested"); | ||
elLayout = page.getByText("Fetched time:"); | ||
newTime = await elLayout.textContent(); | ||
expect(newTime).not.toEqual(time); | ||
|
||
response = await responsePromise; | ||
expect(response.headers()["x-nextjs-cache"]).toEqual("MISS"); | ||
|
||
// If we hit the page again, it should be a hit | ||
responsePromise = page.waitForResponse((response) => { | ||
return response.status() === 200; | ||
}); | ||
await page.goto("/revalidate-tag/nested"); | ||
|
||
response = await responsePromise; | ||
expect(response.headers()["x-nextjs-cache"]).toEqual("HIT"); | ||
}); |
Oops, something went wrong.
abeb9cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
open-next – ./
open-next-git-main-sst-dev.vercel.app
open-next.vercel.app
open-next-sst-dev.vercel.app