infinite loop caused by `isInViewRef`
See original GitHub issueWhen 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:
- Created a year ago
- Reactions:1
- Comments:12 (7 by maintainers)
Top 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 >
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 Free
Top 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
🎉 This issue has been resolved in version 9.4.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
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.