Skip to content

Commit fa0fd78

Browse files
feedthejimclaude
andcommitted
test: verify HTML cache hit with render timestamp
Add render-timestamp outside of 'use cache' function to verify that User B actually gets cached HTML (not a re-render). If the page re-rendered, render-timestamp would differ between User A and User B. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent d76c362 commit fa0fd78

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

test/e2e/app-dir/use-cache/app/(partially-static)/eager-revalidation/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ async function getCachedTimestamp() {
99

1010
export default async function Page() {
1111
const timestamp = await getCachedTimestamp()
12+
// This timestamp is NOT cached - it changes on every render.
13+
// Used to verify HTML cache hits vs re-renders.
14+
const renderTimestamp = Date.now().toString()
1215
return (
1316
<div>
1417
<p id="timestamp">{timestamp}</p>
18+
<p id="render-timestamp">{renderTimestamp}</p>
1519
<form>
1620
<button
1721
id="update-tag"

test/e2e/app-dir/use-cache/use-cache.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,25 +731,35 @@ describe('use-cache', () => {
731731

732732
// Wait for action response
733733
let userAValue: string
734+
let userARenderTimestamp: string
734735
await retry(async () => {
735736
const afterAction = await browser.elementByCss('#timestamp').text()
736737
// KEY ASSERTION: User A sees fresh content immediately (read-your-own-writes)
737738
expect(afterAction).not.toBe(initial)
738739
userAValue = afterAction
740+
userARenderTimestamp = await browser
741+
.elementByCss('#render-timestamp')
742+
.text()
739743
})
740744

741-
// 3. Wait for async HTML cache regeneration
742-
await new Promise((r) => setTimeout(r, 2000))
743-
744-
// 4. Fresh cold visitor (User B) should get same cached HTML
745+
// 3. Fresh cold visitor (User B) should get same cached HTML
746+
// The render-timestamp is NOT cached (changes on each render), so if User B
747+
// sees the same render-timestamp as User A, it proves HTML cache hit (not re-render).
745748
const res = await next.fetch('/eager-revalidation')
746749
const html = await res.text()
747750
const userBValue = html.match(/id="timestamp">(\d+)</)?.[1]
751+
const userBRenderTimestamp = html.match(
752+
/id="render-timestamp">(\d+)</
753+
)?.[1]
748754

749755
// KEY ASSERTION: User B gets the same fresh value as User A (HTML cache was pre-warmed)
750756
expect(userBValue).toBe(userAValue!)
751757

752-
// 5. Verify it's actually cached (second fetch returns same value)
758+
// KEY ASSERTION: Same render timestamp proves HTML cache hit, not re-render
759+
// If the page re-rendered, render-timestamp would be different
760+
expect(userBRenderTimestamp).toBe(userARenderTimestamp!)
761+
762+
// 4. Verify it's actually cached (second fetch returns same value)
753763
const res2 = await next.fetch('/eager-revalidation')
754764
const html2 = await res2.text()
755765
const secondFetch = html2.match(/id="timestamp">(\d+)</)?.[1]

0 commit comments

Comments
 (0)