Skip to content

Fix edges disappearing after node rename#35

Open
CoralCorvusCortex wants to merge 4 commits intomainfrom
hydra/issue-34-edge-after-rename
Open

Fix edges disappearing after node rename#35
CoralCorvusCortex wants to merge 4 commits intomainfrom
hydra/issue-34-edge-after-rename

Conversation

@CoralCorvusCortex
Copy link
Collaborator

Fixes #34.\n\nWhen renaming a node we change its element ID + edge endpoints. Cytoscape element IDs are effectively immutable, and react-cytoscapejs may not fully reconcile this structural change, causing edges to disappear until a full re-render.\n\nThis PR forces a Cytoscape remount when the graph's structural identity (node ids + edge endpoints) changes, so renames reliably keep edges visible.\n\nTests: pnpm test

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 13, 2026

Deploying polycule-graph with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5febbf5
Status: ✅  Deploy successful!
Preview URL: https://0d0074b9.polycule-graph.pages.dev
Branch Preview URL: https://hydra-issue-34-edge-after-re.polycule-graph.pages.dev

View logs

@Corvimia
Copy link
Owner

@CoralCorvusCortex is it possible to force that rerender without forcing a layout change?

@CoralCorvusCortex
Copy link
Collaborator Author

Yes — we can force a Cytoscape re-render/remount without implicitly re-running a layout.

I pushed a follow-up commit to this PR that:

  • always mounts Cytoscape with layout: { name: 'preset' } (so a remount doesn’t shuffle nodes)
  • caches current node positions from the live cy instance and feeds them back into elements on remount
  • still runs COSE once on initial load when there are no DOT positions (via the existing initialLayoutAttemptedRef effect)

Commit: 2dff55b ("Preserve node positions across Cytoscape remount").

So renames will trigger the remount to fix disappearing edges, but the layout/positions should stay as-is.

@Corvimia
Copy link
Owner

That doesn't seem to work. instead, can we save the node's coordinate, and then give it back to the new node?

@CoralCorvusCortex
Copy link
Collaborator Author

CoralCorvusCortex commented Feb 13, 2026

Implemented position preservation on node rename.

  • When you rename a node, we now capture its current Cytoscape coordinates (live if available, otherwise from the cache) and copy them to the new node ID in the ephemeral nodePositionCacheRef.
  • This keeps the node in the same place across the forced Cytoscape remount that happens on structural ID changes.

Change: src/components/GraphView.tsx (renameNodePreservingPosition).

@Corvimia
Copy link
Owner

good work, just last thing: on load we need to refresh layout once

@CoralCorvusCortex
Copy link
Collaborator Author

Implemented the on-load layout refresh.

  • When DOT positions exist, we now run a one-time layout + on first load (after a ), which keeps coordinates but forces Cytoscape to recompute after the container size settles.
  • No change to the existing auto-COSE layout behavior when DOT positions are missing.

Changes:

@CoralCorvusCortex
Copy link
Collaborator Author

Follow-up (previous comment got shell-mangled):

Implemented the on-load layout refresh.

  • When DOT positions exist, we now run a one-time preset layout + fit on first load (after cy.resize()), which keeps coordinates but forces Cytoscape to recompute after the container size settles.
  • No change to the existing auto-COSE layout behavior when DOT positions are missing.

Change: src/components/GraphView.tsx

@CoralCorvusCortex
Copy link
Collaborator Author

Checks: pnpm lint, pnpm test (vitest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: edge disappear after node rename

2 participants