Skip to content
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

Chronic issue with router and exhaustive-deps eslint rule #40791

Open
1 task done
11koukou opened this issue Sep 22, 2022 · 3 comments
Open
1 task done

Chronic issue with router and exhaustive-deps eslint rule #40791

11koukou opened this issue Sep 22, 2022 · 3 comments
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@11koukou
Copy link
Contributor

11koukou commented Sep 22, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Enterprise LTSC 2021
Binaries:
Node: 16.5.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.3.2-canary.3
eslint-config-next: 12.2.2
react: 17.0.2
react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Using router=useRouter() instance inside useEffect triggers ESLint exhaustive-deps rule if not added as a dependency. However trying to fix it and adding router as a dependency leads to unneeded re-renders and potentially infinite loops. There's been an old discussion #18127 for this, however with not a clean solution.

Therefore the example https://nextjs.org/docs/api-reference/next/router#usage-6 in documentation needs URGENT update and needs an official workaround since copy pasting it triggers ESLint exhaustive-deps complaining!

Expected Behavior

useRouter hook should not cause re-renders.

Link to reproduction

https://nextjs.org/docs/api-reference/next/router#usage-6

To Reproduce

https://nextjs.org/docs/api-reference/next/router#usage-6

@11koukou 11koukou added the bug Issue was opened via the bug report template. label Sep 22, 2022
@11koukou
Copy link
Contributor Author

@11koukou
Copy link
Contributor Author

Ok this is partially solved since properly unsubscribing from the router.events in useEffect's "return" prevents unnecessary re-renders but the example needs to be updated anyway with the ESLint rule

@vercel-release-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@vercel-release-bot vercel-release-bot added the stale The issue has not seen recent activity. label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants