Skip to content
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
15 changes: 13 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,31 @@
"node": true,
"jest": true
},
"overrides": [
{
"files": ["e2e/**/*.ts"],
"rules": {
"testing-library/prefer-screen-queries": "off"
}
}
],
"rules": {
"func-names": [2, "as-needed"],
"no-shadow": 0,
"@typescript-eslint/no-shadow": 2,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-unused-vars": [0, {"argsIgnorePattern": "^_"}],
"@typescript-eslint/no-unused-vars": [0, { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/consistent-type-imports": [2, {"prefer": "type-imports"}],
"@typescript-eslint/consistent-type-imports": [
2,
{ "prefer": "type-imports" }
],
"@typescript-eslint/ban-types": 0,
"react-hooks/rules-of-hooks": 2,
"react-hooks/exhaustive-deps": 1,
Expand Down
9 changes: 9 additions & 0 deletions e2e/site/app/issue-2702/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Comp from './reproduction'

export default function Page() {
return (
<div>
<Comp></Comp>
</div>
)
}
41 changes: 41 additions & 0 deletions e2e/site/app/issue-2702/reproduction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use client'
import useSWR, { preload } from 'swr'
import { Suspense, use, useEffect, useState } from 'react'

const sleep = (time: number, data: string) =>
new Promise<string>(resolve => {
setTimeout(() => resolve(data), time)
})

const Bug = () => {
const a = use(preload('a', () => sleep(1000, 'a')))
const { data: b } = useSWR('b', () => sleep(2000, 'b'), {
suspense: true
})
useState(b)
return (
<div>
{a},{b}
</div>
)
}

const Comp = () => {
const [loading, setLoading] = useState(true)

// To prevent SSR
useEffect(() => {
setLoading(false)
}, [])

if (loading) {
return <span>Loading...</span>
}
return (
<Suspense fallback={<div>fetching</div>}>
<Bug></Bug>
</Suspense>
)
}

export default Comp
14 changes: 14 additions & 0 deletions e2e/test/issue-2702-too-many-hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test, expect } from '@playwright/test'

test.describe('issue 2702', () => {
test('should not crash with too many hooks', async ({ page }) => {
// Navigate to the test page
await page.goto('./issue-2702', { waitUntil: 'networkidle' })

// Wait for the page to be fully loaded and interactive
await expect(page.getByText('fetching')).toBeVisible()

// Verify that the component renders correctly
await expect(page.getByText('a,b')).toBeVisible()
})
})
Loading