molecule-core/canvas/src
Hongming Wang 8dbd7efc1a fix(canvas): replace nodes.length grid index with monotonic sequence counter (#388)
Root cause of position collision after node deletion:

  handleCanvasEvent(WORKSPACE_PROVISIONING) used nodes.length as the
  grid placement index. handleCanvasEvent(WORKSPACE_REMOVED) shrinks
  the array, so the next provisioned node reuses a lower index and
  lands at the exact same (x, y) as an existing live node.

  Example (4-col grid, COL_SPACING=320):
    Provision A → idx 0 → (100, 100)
    Provision B → idx 1 → (420, 100)
    Provision C → idx 2 → (740, 100)
    Remove    A → nodes.length drops to 2
    Provision D → idx 2 → (740, 100)  ← COLLISION with C

Fix 1 — monotonic _provisioningSequence counter (only ever increases):
  - Replaces nodes.length as the placement index
  - Immune to deletions; every provisioned node gets a unique grid slot
  - resetProvisioningSequence() exported for test teardown only

Fix 2 — the existing restart-path guard (if exists → update, not create)
  already provides idempotency for duplicate WS events on known nodes;
  confirmed: restart path does NOT increment the counter.

Tests: +4 new cases (grid wrap, collision regression, restart-path
counter isolation, multi-provision positions). 485/485 pass.
Build: next build ✓ clean.

Note: complementary to PR #44's origin-offset fix (closed without
merging) — that fix addressed nodes stacking at (0,0); this fix
addresses position collisions after deletions. Both should land.

Co-authored-by: Canvas Agent <agent@canvas.local>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 00:25:33 -07:00
..
__tests__ fix(a11y): prefers-reduced-motion WCAG 2.3.3 compliance 2026-04-14 11:25:23 +00:00
app Merge pull request #251 from Molecule-AI/feat/cookie-consent-banner 2026-04-15 13:49:53 -07:00
components fix(canvas): show all templates in EmptyState grid, not just first 6 (#387) 2026-04-16 00:19:24 -07:00
hooks initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
lib feat(canvas): /pricing route with plan selector + Stripe checkout 2026-04-15 13:41:44 -07:00
store fix(canvas): replace nodes.length grid index with monotonic sequence counter (#388) 2026-04-16 00:25:33 -07:00
stores initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
styles fix(canvas): dark theme a11y — settings buttons, input fields, ReactFlow colorMode, zinc-400 contrast, aria-labels 2026-04-15 07:56:53 +00:00
types initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
middleware.ts initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00