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.

Cannot add item: item with id <ID> already exists. Graph not updating.

See original GitHub issue

const [graphData, setGraphData] = useState(g1)

// addNode onClick function for button Change Graph.

const addNode = (e) => {
    console.log('addNode clicked!')
<div className='graphContainer'>

graphData is updated with correct data but <Graph> component gives error saying Cannot add item with existing ID but g1 and g2 has nodes with different IDs.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

greysonevinscommented, Apr 17, 2020

@chandrarishabh so I had an example where I select a graph number to load with useState and got the same result of where it breaks from already exists so I added a key prop to the Graph like I would for mapping children and for some reason that resolves it for me.

basically, react needs a way to identify it as a new child of the whole component so that it doesn’t rerender an older one.

                    nodes: graph.nodes.filter(n => === parseInt(selectGroup)),
                    edges: graph.edges.filter(n => === parseInt(selectGroup)),

greysonevinscommented, Apr 20, 2020

@chandrarishabh I made a codesandbox for it

Basically the selectGroup in my case was an id to graph, in this example, I add a new random node and edge to the graph and use a uuid as key.

You’ll see that there are two factors that fix this bug, a deep clone of the graph when reseting or adding a node and the uuid for the key.

I think the issue is that when you manipulate the data as is without deepcloning it, the graph representation of the object tells the Graph that it hasn’t changed and without a key, the wrapper doesn’t know it is a different graph

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot add item: item with id <ID> already ... - Bountysource
Cannot add item : item with id <ID> already exists. Graph not updating. ... // addNode onClick function for button Change Graph. const...
Read more >
Can't create nodes in visjs, ID already exists - Stack Overflow
I set a break point in the code to check the nodes and values and as you can see in the image, the...
Read more >
Microsoft Graph copy sharepoint files item not found and other ...
I received the error that the "item was not found" and the I also included the driveid and got the error "item already...
Read more >
JSON Item Update API - Support - KaiNexus
NOTE: These Attributes and Fields must already exist on the Item's Template in KaiNexus. PRO TIP: The JSON Item Update API cannot be...
Read more >
Participant Import, Update, & Export Messages (EX) - Qualtrics
Failed to update user for new person, username already in use: Unique identifiers were not updated because the new unique IDs from your...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found