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 caused by `isInViewRef`

See original GitHub issue

When calling setRef from this package, it causes an infinite loop if called from within an inline function e.g. when passed as a param to packages like react-merge-ref.

Here’s a simple repro of the issue (calling manually from inside an inline ref callback):

https://codesandbox.io/s/sweet-rgb-6werdb?file=/src/App.js

When an inline ref function is used, React will set the ref to null and back again on every render. So, from my quick dive into this package’s code I believe this caveat is causing the observer to set up again which is firing setState and re-rendering, which calls setRef with null (and back again), and loops.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
thebuildercommented, Jul 22, 2022

🎉 This issue has been resolved in version 9.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
jjenzzcommented, Jul 6, 2022

There’s no perfect way to solve this (that I’m aware of)

The lib is calling setState with a new object reference regardless of whether the intersection value has actually changed (causing an infinite loop). Checking for change there would prevent it:

Another approach is to take advantage of React’s batching to set the node in state:

https://codesandbox.io/s/fervent-wood-h7jj1g?file=/src/App.js

There are likely other ways I haven’t considered but it does seem that the lib should be able to handle it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent an infinite loop call while assigning element a ...
I have encountered a problem assigning an element's value to a service. In this scenario, the value of the component is populated with...
Read more >
The Curious Case of Angular and the Infinite Change Event ...
We have just entered an endless event loop and my Macbook Pro gave me third-degree burns on my thighs. computer-fire. The Fix. So...
Read more >
sentry/angular cause infinite re-render loop #2974 - GitHub
The Sentry intializer starts an infinite re-render loop that start consuming a lot of CPU and if there any sort of console.log or...
Read more >
UNPKG - @angular/core
n * Recursive loop causes an error to be displayed. ... us to\n // find the own factory first and potentially triggering an...
Read more >
Untitled
Oeroude bomen krachtige stromen, Wood stove reviews 2013, Pariisin kartta pariisi. ... 64 km melbourne airport radar loop, Carrie interdentaire, ...
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