Fix EdgeDraw reactivity to Python-side name changes (0.5.24) - #321
Merged
Conversation
EdgeDraw's frontend read `names` only once at init and registered change handlers for `links`/`directed` but not `names`, so adding or removing nodes from Python never updated the drawing. Add a `change:names` handler that rebuilds nodes (reusing positions for survivors), prunes links pointing at removed nodes (syncing them back), and restarts the force simulation. Also demos the runtime add/remove-node pattern and bumps the release to 0.5.24. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What & why
Reported via r/marimo_notebook: adding/removing nodes on an
EdgeDrawfrom Python did nothing. Two causes:widget.names.append(...)mutates in place, and traitlets only fires on reassignment — so it never syncs. Documented in the demo.namesonly once at init and registeredchangehandlers forlinks/directedbut notnames, so Python-side node changes never rendered.Changes
js/edgedraw.js(+ rebuiltwigglystuff/static/edgedraw.js): add achange:nameshandler that rebuilds nodes (reusing positions for survivors, spawning new ones at center), rebuilds the id maps, clears stale selection, prunes links pointing at removed nodes (and syncs them back to Python), re-binds the.node/.labelselections keyed by id, and restarts the force simulation. Promoted the mutated closure bindings fromconsttolet.demos/edgedraw.py: new "Editing nodes from Python" section (text box + Add/Remove buttons using reassignment) with a note on why.append()doesn't work. Bumped the PEP 723 pin to0.5.24.pyproject.toml/uv.lock→0.5.24,CHANGELOG.mdentry under### Fixed.Verification
uv run pytest tests/test_edgedraw.py→ 5 passeduv run marimo check demos/edgedraw.py→ cleanwidget.namesadd/remove works; links preserved🤖 Generated with Claude Code