Skip to content

fix: palette-add mints unique node ids against live topology - #1

Draft
Dahhrk wants to merge 2 commits into
mainfrom
cursor/fix-palette-add-duplicate-ids-39bf
Draft

fix: palette-add mints unique node ids against live topology#1
Dahhrk wants to merge 2 commits into
mainfrom
cursor/fix-palette-add-duplicate-ids-39bf

Conversation

@Dahhrk

@Dahhrk Dahhrk commented Sep 3, 2026

Copy link
Copy Markdown
Owner

What this changes

Palette-add (handleAddNode) now mints node ids against the live topology mirror instead of a module counter that resets on page load. Closes xevrion#46.

Why

makeNode uses a module-level nodeCounter that resets on load. Two palette-adds of the same kind mint the same id. isTopology rejects the save, and loadSession silently falls back to PRESETS[0].

Changes

  • src/clipboard.ts: export freshId (contract unchanged)
  • src/App.tsx: handleAddNode reads topoLiveRef.current (not the React topology closure), overrides id with freshId, and drops topology from the dependency array. Two rapid adds no longer drop the first node.
  • src/clipboard.test.ts: freshId unit tests (unique mints, skip-existing, isTopology accepts)
  • src/handleAddNode.wiring.test.ts (new):
    • Source wiring assertion: handleAddNode spreads topoLiveRef.current, not the React topology binding; freshId is called; topology is not in the dep array.
    • Behavioral test: two sequential cache adds against the default preset (client, api, db) with no intervening render. Both nodes survive, ids are unique, isTopology accepts.

Verification

$ bun run test
 Test Files  37 passed (37)
      Tests  904 passed (904)

$ bun run build   # tsc -b && vite build
✓ clean

$ bun run lint
Pre-existing warnings only, no new issues.
  • bun run test passes (904 tests, 37 files)
  • bun run typecheck and bun run lint pass
  • bun run build passes
  • Screenshot attached, if anything visual changed

GitHub CI

No GitHub Actions check_runs exist on this repo. The only status is Vercel deployment, which reports "Authorization required to deploy" (not a CI gate, not proof of correctness).

GET /repos/xevrion/breakscale/commits/0a76206/check-runs → {"total_count": 0, "check_runs": []}
GET /repos/xevrion/breakscale/commits/0a76206/statuses → [{"context": "Vercel", "state": "failure", "target_url": "…/authorize…"}]

Keep

Upstream PR (same branch): xevrion#47

Open in Web Open in Cursor 

makeNode uses a module counter that resets on page load, causing
duplicate ids when adding nodes of the same kind. handleAddNode now
overrides the id using freshId (exported from clipboard.ts), which
scans the live node id set — matching the pattern freshAnnId already
uses for annotations.

Closes xevrion#46
…ral tests

handleAddNode now reads topoLiveRef.current instead of the React
topology closure, preventing two rapid adds from dropping the first
node. topology removed from the dependency array.

New test file handleAddNode.wiring.test.ts:
- Source assertion: handleAddNode spreads topoLiveRef.current, not
  the React topology binding, and freshId is called.
- Behavioral test: two sequential cache adds against the default
  preset produce unique ids, both nodes survive, isTopology accepts.
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

Successfully merging this pull request may close these issues.

Adding a component from the rail can mint a duplicate id, and the next reload silently discards the design

2 participants