Infinite loop when both arguments have cycles
See original GitHub issueIf both arguments have cycles, like if you’re trying to compare doubly-linked lists, dequal goes into an infinite loop.
repro:
const a: any = {}, b: any = {};
a.next = b;
b.previous = a;
const c: any = {}, d: any = {};
c.next = d;
d.previous = c;
dequal(a, c);
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to Solve the Infinite Loop of React.useEffect()
1.1 Fixing dependencies ... The infinite loop is fixed by correct management of the useEffect(callback, dependencies) dependencies argument.
Read more >Why wouldn't breaking-retain-cycle fall into infinite-loop like this?
When you release an object with a retain count of 1, the following happens: The object is marked as "dead". The dealloc method...
Read more >How to solve the React useEffect Hook's infinite loop patterns
Solve the issue of infinite loops when using the useEffect Hook in React to more smoothly utilize the Hook for your app's side...
Read more >Infinitely Cycle Through an Array - KIRUPA
In the looping through an array article, we looked at the various looping mechanisms we have for going through each item in our...
Read more >Top 4 Types of Statements in Python Infinite Loop - eduCBA
It is to be noted that the statements that are executed after the while loop can be a single line or even a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I may add a
dequal/circular
mode so that users opt into the added checks only when necessary. While my use case is certainly not everyone’s use case, I’ve never run into this IRL because generally I avoid circular references, especially in something like a UI Component’s state, where “is expensive-X the same as expensive-Y” comes up.Offering it as a module means that it’s an easy import (or import alias) away. There’d be no API changes. Would be the same pattern as
dequal
vsdequal/lite
now.Also, re: React. @justinfagnani is right here; there definitely should not be a React-specific offering here. A solution for all circulars is a solution for React. But on that note,
fast-deep-equal/react
might not do what you think @yuri-scarbaci-lenio … it just skips/avoids the problem.Don’t quite have the bandwidth to get into everything you brought up right now, but I will later. For now:
It would just be
dequal
,dequal/lite
, anddequal/circular
. Initially, I almost broke out adequal/json
(supports less than/lite
), but IIRC it was only about 80b smaller and not mega-significantly faster thandequal/lite
on its own.I know this might seem unrelated, but it’s to say that I don’t think of these as “permutations” – instead, they’re expanding scopes/feature sets. The scope coverage depends on the size of the umbrella you pick.
Supporting circular references already implies complex objects, which needs to include
dequal
by default anyway, and so Circulars is an additive, opt-in feature to that.