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

[Fix] jsx-max-depth: Prevent getting stuck in circular references #2957

Merged
merged 1 commit into from Apr 7, 2021

Conversation

AriPerkkio
Copy link
Contributor

Fixes #2880.

What:

findJSXElementOrFragment is getting stuck if given variable A references variable B, while variable B also references variable A (directly or via another references).

How:

Before calling method recursively, check whether we have already checked references of the variable.

Test plan:

Unit tests:

  1. Simple circular reference check for a single level
  2. Complex circular reference check for multiple levels. Makes sure previousReferences is passed through the whole call chain, instead of just a single call.

Regression:

Ran eslint-remote-tester in comparison mode against 500 repositories. First run caught ~86K ESLint reports. Second call (with the fix) was identical except the old crash being missing. Results: AriPerkkio#1 (comment)

I had to do couple of iterations of refactoring due to node4 job failing (function default props, spread syntax, Array.includes).
Ready to change any part of the changes if required.

@ljharb ljharb force-pushed the fix/jsx-max-depth branch 2 times, most recently from 8309daf to 7ce9106 Compare April 7, 2021 07:00
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use array-includes; updated to use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

jsx-max-depth: Maximum call stack size exceeded
2 participants