Skip to content

fix use cache flaky test #849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion examples/experimental/src/app/use-cache/ssr/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FullyCachedComponent, ISRComponent } from "@/components/cached";
import {
FullyCachedComponent,
FullyCachedComponentWithTag,
ISRComponent,
} from "@/components/cached";
import { headers } from "next/headers";
import { Suspense } from "react";

Expand All @@ -12,6 +16,9 @@ export default async function Page() {
<Suspense fallback={<p>Loading...</p>}>
<FullyCachedComponent />
</Suspense>
<Suspense fallback={<p>Loading...</p>}>
<FullyCachedComponentWithTag />
</Suspense>
<Suspense fallback={<p>Loading...</p>}>
<ISRComponent />
</Suspense>
Expand Down
11 changes: 10 additions & 1 deletion examples/experimental/src/components/cached.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { unstable_cacheLife, unstable_cacheTag } from "next/cache";

export async function FullyCachedComponent() {
"use cache";
return (
<div>
<p data-testid="fully-cached">{Date.now()}</p>
</div>
);
}

export async function FullyCachedComponentWithTag() {
"use cache";
unstable_cacheTag("fullyTagged");
return (
<div>
<p data-testid="fullyCached">{Date.now()}</p>
<p data-testid="fully-cached-with-tag">{Date.now()}</p>
</div>
);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/tests-e2e/tests/experimental/use-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from "@playwright/test";
test.describe("Composable Cache", () => {
test("cached component should work in ssr", async ({ page }) => {
await page.goto("/use-cache/ssr");
let fullyCachedElt = page.getByTestId("fullyCached");
let fullyCachedElt = page.getByTestId("fully-cached");
let isrElt = page.getByTestId("isr");
await expect(fullyCachedElt).toBeVisible();
await expect(isrElt).toBeVisible();
Expand All @@ -15,7 +15,7 @@ test.describe("Composable Cache", () => {

do {
await page.reload();
fullyCachedElt = page.getByTestId("fullyCached");
fullyCachedElt = page.getByTestId("fully-cached");
isrElt = page.getByTestId("isr");
await expect(fullyCachedElt).toBeVisible();
await expect(isrElt).toBeVisible();
Expand All @@ -31,7 +31,7 @@ test.describe("Composable Cache", () => {
request,
}) => {
await page.goto("/use-cache/ssr");
const fullyCachedElt = page.getByTestId("fullyCached");
const fullyCachedElt = page.getByTestId("fully-cached-with-tag");
await expect(fullyCachedElt).toBeVisible();

const initialFullyCachedText = await fullyCachedElt.textContent();
Expand All @@ -49,7 +49,7 @@ test.describe("Composable Cache", () => {
test("cached component should work in isr", async ({ page }) => {
await page.goto("/use-cache/isr");

let fullyCachedElt = page.getByTestId("fullyCached");
let fullyCachedElt = page.getByTestId("fully-cached");
let isrElt = page.getByTestId("isr");

await expect(fullyCachedElt).toBeVisible();
Expand All @@ -65,7 +65,7 @@ test.describe("Composable Cache", () => {
while (isrText === initialIsrText) {
await page.reload();
isrElt = page.getByTestId("isr");
fullyCachedElt = page.getByTestId("fullyCached");
fullyCachedElt = page.getByTestId("fully-cached");
await expect(isrElt).toBeVisible();
isrText = await isrElt.textContent();
await expect(fullyCachedElt).toBeVisible();
Expand All @@ -76,7 +76,7 @@ test.describe("Composable Cache", () => {

do {
await page.reload();
fullyCachedElt = page.getByTestId("fullyCached");
fullyCachedElt = page.getByTestId("fully-cached");
isrElt = page.getByTestId("isr");
await expect(fullyCachedElt).toBeVisible();
await expect(isrElt).toBeVisible();
Expand Down
Loading