Skip to content

Commit 30b4c81

Browse files
committed
[test] Add a failing test for cycle serialization in segment prefetches
Requires a fix in React to pass (possibly facebook/react#35471). closes #86401
1 parent 669b3e7 commit 30b4c81

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use client'
2+
3+
export function ClientComponent({ testProp }: { testProp: { self: unknown } }) {
4+
return (
5+
<div id="cycle-check">
6+
{testProp.self === testProp ? 'Cycle resolved' : 'Cycle broken'}
7+
</div>
8+
)
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ClientComponent } from './client'
2+
3+
export default async function Page() {
4+
const cycle = { self: null as unknown }
5+
cycle.self = cycle
6+
7+
return <ClientComponent testProp={cycle} />
8+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { LinkAccordion } from '../components/link-accordion'
22

33
export default function Page() {
4-
return <LinkAccordion href="/test">Go to test page</LinkAccordion>
4+
return (
5+
<>
6+
<p>
7+
<LinkAccordion href="/test">Go to test page</LinkAccordion>
8+
</p>
9+
<p>
10+
<LinkAccordion href="/cycle">Go to cycle page</LinkAccordion>
11+
</p>
12+
</>
13+
)
514
}

test/e2e/app-dir/segment-cache/basic/segment-cache-basic.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,43 @@ describe('segment cache (basic tests)', () => {
412412
const content = await page.textContent()
413413
expect(content).toContain('Cache Life Seconds Page')
414414
})
415+
416+
// TODO: Requires a fix in React.
417+
it.failing(
418+
'can handle circular references in client component props',
419+
async () => {
420+
let act: ReturnType<typeof createRouterAct>
421+
const browser = await next.browser('/', {
422+
beforePageLoad(page) {
423+
act = createRouterAct(page)
424+
},
425+
})
426+
427+
// Reveal the link to trigger a prefetch.
428+
const link = await act(
429+
async () => {
430+
await browser
431+
.elementByCss('input[data-link-accordion="/cycle"]')
432+
.click()
433+
return browser.elementByCss('a[href="/cycle"]')
434+
},
435+
{ includes: 'testProp' }
436+
)
437+
438+
await act(
439+
async () => {
440+
await link.click()
441+
442+
// The page should render immediately because it was prefetched, and it
443+
// should show the resolved cycle text.
444+
expect(await browser.elementById('cycle-check').text()).toBe(
445+
'Cycle resolved'
446+
)
447+
},
448+
// No additional requests were required, because everything was
449+
// prefetched.
450+
'no-requests'
451+
)
452+
}
453+
)
415454
})

0 commit comments

Comments
 (0)