Repository navigation
Conversation
Phase 4a of the declutter plan. The six handlers that lay nodes out or
route edges each carried a copy of "walk the model, key the nodes and
the routes, save": eight collectNodePositions, eight collectEdgeRoutes,
five signature helpers, four snapshot/restore sets, about 1,400 lines,
drifted in formatting, in types and in two places in meaning.
server/layout-snapshot.ts holds them once, and persisted-edge-routes.ts
exports the route-key and anchor helpers it always had. persistLayout
replaces the seven save blocks; the one in runBoundaryFlowAndPersist
keeps its own meta and calls the collectors.
Two drifts end here: Reset Routes and the reroute noted their save under
a model-state key nothing read ('workflow.layoutPersistence' instead of
the shared constant), and four handlers keyed routes by AST path alone
where the loader and the other writers key by endpoint signature.
Claude-Session: https://claude.ai/code/session_01EToj6RJRMSSHQiqGNMU9wv
Reset Routes and the reroute leave the layout meta alone on purpose: their old note went to a key nothing read, and writing it where the rest of the server reads it would have lowered "has persisted edge routes" and armed the bootstrap reroute, which redraws what was just cleared. A lone bend is saved as before: the loader rebuilds it into a full polyline. The bend handler keeps its own port-anchor helper, which accepts any end with a node above it where the loader's wants a port. One save path: runBoundaryFlowAndPersist goes through persistLayout, placeNewNodes keys nodes with the shared nodeLayoutKeyOf, the inline layout-meta types are the one LayoutPersistenceMeta, Point comes from the routes module, and the reroute's persist drops a parameter it no longer read. Claude-Session: https://claude.ai/code/session_01EToj6RJRMSSHQiqGNMU9wv
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.
Phase 4a of the declutter plan (de-duplication, server side). Pure refactor inside
diagram-server, plus two small fixes the consolidation forced into the open.What was duplicated
Every handler that lays nodes out or routes edges ended the same way: walk the GModel, key nodes by AST path / entity name / port name, key edges, save, update the layout meta. Each had its own private copy:
collectNodePositions,collectEdgeRoutesdiagram-action-handlers.ts)edgeSignatureFromArgs,buildEdgeSignatureCounts,edgeRouteKeyForpersisted-edge-routes.tsis the loader's)snapshotNodePositionsById,snapshotEdgeRoutesById,restoreUnselectedLayout,getSelectedMovableNodeIds,isMovableNode,getMovableNodeIdForElementIdabsolutePosition,portAnchorAbsoluteA diff of all copies (done before writing) showed differences of formatting and parameter types, plus two of meaning, below.
What this PR does
src/server/layout-snapshot.ts:isMovableNode,movableNodeIdFor,movableNodeIdsIn,snapshotNodePositionsById,snapshotEdgeRoutesById,restoreUnselectedLayout,collectNodePositions,collectEdgeRoutes,LayoutPersistenceMeta, andpersistLayout(modelState, layoutPersistence, { layoutPerformed?, keepPersistedPositions? }), which replaces the seven near-identical save blocks (the reset and bend handlers keep the positions already on disk; the layout handlers mark the layout persisted).src/routing/persisted-edge-routes.tsexportsabsolutePosition,portAnchorAbsolute,edgeSignatureFromArgs,buildEdgeSignatureCounts,edgeRouteKeyFor(they were module-private); the change-routing-points handler uses the loader'sportAnchorAbsolute(same geometry via sharedportAnchor) instead of its own.runBoundaryFlowAndPersistkeeps its own meta object (it is handed one) and calls the two collectors.absolutePosition(it sumsGNodeancestors only, a different rule for its own port geometry) andsimplifyRoutingPoints(still called).The two meaning drifts, and what the review made of them
'workflow.layoutPersistence'while everything else usesWORKFLOW_LAYOUT_PERSISTENCE_KEY, so their note never landed. The first version of this PR routed them through the shared key; the review showed that loweringhasPersistedEdgeRoutesafter a reset arms the ModelSubmissionHandler's bootstrap reroute, which would redraw what was just cleared. They now callpersistLayout(..., { noteInMeta: false }): the save happens, the meta is left alone, and the comment says why.collectEdgeRoutesnow, keyed as the loader reads. A lone bend is still saved (the loader rebuilds it into a full polyline); the first version dropped it, the review caught it.Also from the review: the bend handler keeps its own
portAnchorAbsolute(it accepts any end with a node above it, where the loader's requires aGPort);runBoundaryFlowAndPersistgoes throughpersistLayouttoo;placeNewNodesuses the sharednodeLayoutKeyOf; the four inline layout-meta types are the oneLayoutPersistenceMeta;Pointcomes from the routes module; the reroute'spersistRoutesdrops therootparameter it no longer read.Tests
layout-snapshot.test.ts: node keys and absolute positions through a nested group, route keys by signature, the selection's movable nodes (element, edge ends, nested node), restore of the unselected part, andpersistLayoutin its three modes. Existing coverage: reroute-keeps-the-layouts-trunk, persisted-edge-routes-snap-to-ports, glsp-auto-layout-clears-routes, per-instance-layout.Diff: 7 files, +69/−1470 in the handlers, +1 module (~230 lines), +1 test. Typecheck 5/5, neutrality 5/5, server 449 tests.
Note: this branch is cut from main before #119 and #120 merged; only
CHANGELOG.mdcan conflict, and I will rebase onto main on a fresh branch if it does.https://claude.ai/code/session_01EToj6RJRMSSHQiqGNMU9wv