Passing ref from useResource to line materials results in infinite render
See original GitHub issueHi, 👋
I’ve encountered some weird behaviour that seems to create an infinite render loop.
If passing a ref from useResource to a line material such as <lineBasicMaterial /> it seems to get into an infinite render loop. If passing a ref from useRef this does not seem to happen, so I believe we can narrow it down to the useResource hook.
In my own environment it just never stops rendering the component (it doesn’t hang though). In this example is just hangs and becomes completely unresponsive: https://codesandbox.io/s/react-three-fiber-react-spring-42187
In my own environment I’m using useResource to draw a lot of lines, hence why I would like to reuse the same material.
Hope this is solvable!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
useResource may go into an infinite render loop if given a ...
This works fine for the string and Resource case, but it doesn't behave well for the Promise<Resource> case. As a result, doing: const...
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 >Infinite loop in useEffect - reactjs - Stack Overflow
Passing an empty array as the second argument to useEffect makes it only run on mount and unmount, thus stopping any infinite loops....
Read more >Forwarding Refs - React
Ref forwarding is a technique for automatically passing a ref through a component to one of its children. This is typically not necessary...
Read more >C++ Core Guidelines - GitHub Pages
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++.
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

PS! I just realised the reason
invalidateFrameloopnever worked for me was because of the infinite render loop. Never understood why it didn’t work. Now it works properly 👏Ah, interesting. So it’s either doing that or having different functionality for updating different non-changable values? i.e. having specific way to treat changes to geometries and other type of items.
I checked Three’s own way of changing geometry properties from their demos. But as you said, they are recreating it on every change too:
source: https://threejs.org/docs/scenes/js/geometry.js