Skip to content

Commit 5d421a6

Browse files
authored
test: e2e test for 2702 (#4154)
1 parent be1799d commit 5d421a6

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

.eslintrc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,31 @@
3131
"node": true,
3232
"jest": true
3333
},
34+
"overrides": [
35+
{
36+
"files": ["e2e/**/*.ts"],
37+
"rules": {
38+
"testing-library/prefer-screen-queries": "off"
39+
}
40+
}
41+
],
3442
"rules": {
3543
"func-names": [2, "as-needed"],
3644
"no-shadow": 0,
3745
"@typescript-eslint/no-shadow": 2,
3846
"@typescript-eslint/explicit-function-return-type": 0,
39-
"@typescript-eslint/no-unused-vars": [0, {"argsIgnorePattern": "^_"}],
47+
"@typescript-eslint/no-unused-vars": [0, { "argsIgnorePattern": "^_" }],
4048
"@typescript-eslint/no-use-before-define": 0,
4149
"@typescript-eslint/ban-ts-ignore": 0,
4250
"@typescript-eslint/no-empty-function": 0,
4351
"@typescript-eslint/ban-ts-comment": 0,
4452
"@typescript-eslint/no-var-requires": 0,
4553
"@typescript-eslint/no-explicit-any": 0,
4654
"@typescript-eslint/explicit-module-boundary-types": 0,
47-
"@typescript-eslint/consistent-type-imports": [2, {"prefer": "type-imports"}],
55+
"@typescript-eslint/consistent-type-imports": [
56+
2,
57+
{ "prefer": "type-imports" }
58+
],
4859
"@typescript-eslint/ban-types": 0,
4960
"react-hooks/rules-of-hooks": 2,
5061
"react-hooks/exhaustive-deps": 1,

e2e/site/app/issue-2702/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Comp from './reproduction'
2+
3+
export default function Page() {
4+
return (
5+
<div>
6+
<Comp></Comp>
7+
</div>
8+
)
9+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use client'
2+
import useSWR, { preload } from 'swr'
3+
import { Suspense, use, useEffect, useState } from 'react'
4+
5+
const sleep = (time: number, data: string) =>
6+
new Promise<string>(resolve => {
7+
setTimeout(() => resolve(data), time)
8+
})
9+
10+
const Bug = () => {
11+
const a = use(preload('a', () => sleep(1000, 'a')))
12+
const { data: b } = useSWR('b', () => sleep(2000, 'b'), {
13+
suspense: true
14+
})
15+
useState(b)
16+
return (
17+
<div>
18+
{a},{b}
19+
</div>
20+
)
21+
}
22+
23+
const Comp = () => {
24+
const [loading, setLoading] = useState(true)
25+
26+
// To prevent SSR
27+
useEffect(() => {
28+
setLoading(false)
29+
}, [])
30+
31+
if (loading) {
32+
return <span>Loading...</span>
33+
}
34+
return (
35+
<Suspense fallback={<div>fetching</div>}>
36+
<Bug></Bug>
37+
</Suspense>
38+
)
39+
}
40+
41+
export default Comp
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test.describe('issue 2702', () => {
4+
test('should not crash with too many hooks', async ({ page }) => {
5+
// Navigate to the test page
6+
await page.goto('./issue-2702', { waitUntil: 'networkidle' })
7+
8+
// Wait for the page to be fully loaded and interactive
9+
await expect(page.getByText('fetching')).toBeVisible()
10+
11+
// Verify that the component renders correctly
12+
await expect(page.getByText('a,b')).toBeVisible()
13+
})
14+
})

0 commit comments

Comments
 (0)