Skip to content

fix: Keep the selection when a view is mounted again - #101

Merged
philippjfr merged 1 commit into
mainfrom
fix/remount-selection-2
Nov 22, 2026
Merged

philippjfr merged 1 commit into
mainfrom
fix/remount-selection-2

Conversation

@philippjfr

Copy link
Copy Markdown
Contributor

When a ReactFlow view is mounted again, for example when a dynamic tab hides and re-shows the canvas, the new view sent an empty selection and cleared the selection in Python. Python stores a browser selection on its nodes' selected flags without syncing them back, so the fresh view hydrated nodes that were all unselected, React Flow reported an empty selection, and that differed from the selection parameter, so it was sent.

I now start a view's nodes and edges from the selection parameter, treat the flags the view started from as the baseline for later node syncs (so a stale selected flag does not read as Python selecting a node), and skip React Flow's empty first report when the view starts with a selection. Clicking the pane still deselects.

I added a UI test that selects a node, then an edge, re-mounts the flow in a dynamic pn.Tabs each time and checks the selection is kept and no selection_changed fires, then clicks the pane to deselect. It fails on main. The full UI suite (160) and unit tests pass, as does panel-flowdash's tests/ui/test_ui_sidecar_selection.py against this branch. Once this is released, panel-flowdash can drop the 3 s selection window and the flow._process_msg wrapper added in panel-flowdash#246.

Test timing fix

test_connection_validation_demo started dragging right after the page served. It only passed because main's mount sent an extra selection round trip; it now waits for the initial fitView with _wait_for_viewport, like the other drag tests, since a fitView landing mid-drag turns the drag into a pan.

A newly mounted view started from nodes whose selected flags Python had
not synced, so React Flow reported an empty selection and cleared it.
Start the view's nodes and edges from the selection parameter, treat the
flags it started from as the baseline for later node syncs, and skip
React Flow's empty mount report.
@philippjfr
philippjfr marked this pull request as ready for review November 22, 2026 08:24
@philippjfr
philippjfr merged commit 3f34374 into main Nov 22, 2026
17 checks passed
@philippjfr
philippjfr deleted the fix/remount-selection-2 branch November 22, 2026 08:24
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.

1 participant