fix: never mint a node id that is already on the canvas - #65
Open
yeabsira-gashaw wants to merge 1 commit into
Open
fix: never mint a node id that is already on the canvas#65yeabsira-gashaw wants to merge 1 commit into
yeabsira-gashaw wants to merge 1 commit into
Conversation
makeNode's counter restarts at zero on every page load, but the ids it minted earlier come back through localStorage, share links and design files. Adding a component after a reload could therefore reuse an id already on the canvas, and two nodes then shared one id: selecting one selected both, the inspector read "2 components", and edges and config changes applied to both. The add path now skips ids the topology already holds, the way the paste path always has.
|
Someone is attempting to deploy a commit to the whoarrryou's projects Team on Vercel. A member of the Team first needs to authorize it. |
Owner
|
Putting the dedupe inside One change before I merge: Credit where due, #47 found that stale closure first. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding a component from the palette could reuse an id that a node on the canvas already had.
makeNodenumbers new nodes from a module counter that restarts at zero on every page load, while the ids it minted in earlier sessions come back through localStorage, share links and design files. After a reload of a design holdingservice-1toservice-10, the next add wasservice-1again.Two nodes then shared one id, and everything keyed by id conflated them: selecting either selected both (the inspector read "2 components"), an edge drawn to one landed on both, and a config change applied to both. It only happens after a reload of a restored design, which is why it looks intermittent, and it gets more likely as the canvas grows.
Fix
makeNodetakes the set of ids already on the canvas and skips past any it would collide with, andhandleAddNodeinApp.tsxpasses that set. This is the same dedupe the paste and duplicate paths already do throughfreshIdinclipboard.ts; the add path was the only one without it.Before / after
Headless, with
service-1..service-10on the canvas and the counter at zero (a fresh page load):Before: the newly added service shares an id with an existing one, so the inspector reads "2 components" and edits apply to both.
After: the new node gets its own id and is the only thing selected.
Tests
src/sim/makeNode.ids.test.tscovers a single add against taken ids and repeated adds staying distinct.bun run testandbun run buildpass locally.