Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Lenostatos opened this issue Aug 30, 2023 · 2 comments
Open

Comments

@Lenostatos
Copy link

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?

@BOJIT
Copy link
Contributor

BOJIT commented Aug 30, 2023

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.

@Lenostatos
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants