pycodestyle icon indicating copy to clipboard operation
pycodestyle copied to clipboard

Rendering an array of nodes is buggy when the Node component's id is set

Open Lenostatos opened this issue 2 years ago • 2 comments

I created a code example at https://stackblitz.com/edit/svelvet-v7-zrfaxy?file=src%2Froutes%2F%2Bpage.svelte

There, an array of nodes with random positions is rendered on the canvas when clicking the "new node" button. The problematic code is the id="55" bit in line 34. As long as that is there, the deletion of a single node makes all other nodes vanish from the canvas and they only appear again once a new node is added. Removing the id="55" bit fixes the bug.

I stumbled upon this because I copied the code example from https://svelvet.mintlify.app/components/node and forgot to delete the id="55" bit. Is it possible to avoid that bug for others in the future by e.g. issuing a warning on the command line in situations like these?

Lenostatos avatar Aug 30 '23 10:08 Lenostatos

I believe the ID overrides the Svelvet Node's id attribute, which is used as a unique identifier in an HTML document. If all nodes in your graph have the same ID, then deleting one will delete all of them, as they all have the same ID attribute.

I guess the library could warn if multiple components are instantiated with the same ID, however I'd argue it's up to the application to ensure that the IDs are unique.

BOJIT avatar Aug 30 '23 16:08 BOJIT

Ah, I see. Yes, it's definitely my bad, that I gave every Node the same ID with that :sweat_smile: . I think a warning like you said would be nice though, if it's not too much of a hassle.

Lenostatos avatar Sep 04 '23 09:09 Lenostatos