question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop when both arguments have cycles

See original GitHub issue

If 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:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
lukeedcommented, Sep 7, 2021

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 vs dequal/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.

3reactions
lukeedcommented, Sep 7, 2021

Don’t quite have the bandwidth to get into everything you brought up right now, but I will later. For now:

would that implies you will also have the permutations?

It would just be dequal, dequal/lite, and dequal/circular. Initially, I almost broke out a dequal/json (supports less than /lite), but IIRC it was only about 80b smaller and not mega-significantly faster than dequal/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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found