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.

V10 API Example - Infinite loop ?

See original GitHub issue
import ReactFlow, {
  applyNodeChanges,
  applyEdgeChanges
} from 'react-flow-renderer';

const initialNodes = [
  { id: '1', data: { label: 'Node 1' }, position: { x: 250, y: 0 } },
  { id: '2', data: { label: 'Node 2' }, position: { x: 150, y: 100 } }
];

const initialEdges = [
  { id: 'e1-2', source: '1', target: '2' }
];

const BasicFlow = () => {
  const [nodes, setNodes] = useState(initialNodes);
  const [edges, setEdges] = useState(initialEdges);

  const onNodesChange = useCallback((changes) => setNodes((ns) => applyNodeChanges(changes, ns)), []);
  const onEdgesChange = useCallback((changes) => setEdges((es) => applyEdgeChanges(changes, es)), []);

  return (
    <ReactFlow
      nodes={nodes} 
      edges={edges}
      onNodesChange={onNodesChange}
      onEdgesChange={onEdgesChange}
    />
  );
};

export default BasicFlow;

Using: react-flow-renderer@10.0.0-next.28

It appears that once

nodeTypes = { { } }

is added to the API example that, there is a pretty serious loop occuring ? am I missing something. applyNodeChanges is triggering onNodesChange which is then calling the callback and on and on etc.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rithvikvibhucommented, Dec 19, 2021

Thanks @moklick I did search the issues the day before this issue was created, that’s a real coincidence :p Anyway, just wanted to say that memoizing outside the function worked. I see the PR description has also been updated, cheers!

1reaction
moklickcommented, Dec 17, 2021

Good point. I will add it to the docs. We are not memoizing node types anymore. If your node types were dynamic you had to use a hacky API to update them in v9. In v10 it behaves like all other props too. You need to take care that you don’t create a new nodeTypes object on every render. If you use useMemo or define the nodeTypes outside of the component this issue shouldn’t occur. Does this solve your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

require.main can go into an infinite loop #10478 - GitHub
5. When module tries to call require.main , we now have a cyclic dependency, and the while loop that determines main goes ...
Read more >
Infinite loop after some hours inactivity with @auth0/nextjs-auth0
Hello everyone! In our product we use Next.js v10.0.8 an also the corresponding Auth0 SDK @auth0/nextjs-auth0 in Version ^1.4.0 for user ...
Read more >
What if I accidentally run an infinite loop that reads data from ...
Someone can just open up dev tools on my website and run an infinite loop that read data from my database. This would...
Read more >
Detecting and avoiding infinite loops in the menus API JSON
This configuration can create an infinite loop that prevents a menu from being resolved. If your integration encounters a modifier option whose item ......
Read more >
Workaround for infinite loop bug in Google Ads API - Oribi
However, when the request has an error, such as "permission denied", we never get an answer. It seems the callable is stuck on...
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