Repository navigation
refactor(core): dedupe mechanical duplication in renderer/layout.ts - #2516
Merged
Merged
Conversation
…n layout The layering phase (grouped bands -> forced kind tiers -> topological fallback -> direction hints) and the group-title-gap start-layer map were textually duplicated between layoutInner and layoutMultipleSystems. Extract both into module-private helpers consumed by the two paths so they cannot drift (TPL-219). Pure code motion; no behavior change. Refs #2512
The ten derived LayoutNode fields were written out as five near-identical object literals (ghost users, ghost rows, single-system placement, ghost-system services, multi-system placement). Fold them into one module-private constructor; label/annotation/owner/ghost resolution stays at each call site. Conditional spread keeps subLabel/ghost keys present only where the original literals had them, so object shapes are unchanged. Pure code motion; no behavior change. Refs #2512
…object Eight positional parameters with adjacent same-typed slots are the exact slot-swap hazard the LayoutOptions doc cites (#1875). Convert to a destructured options object and reattach the function's JSDoc, which had been orphaned 85 lines above it by an interleaved doc block. No behavior change. Refs #2512
…d isGhost - Extract centerRowsHorizontally for the single- and multi-system placement phases. The two blocks sorted and summed in opposite orders, which is equivalent: the row width is a sum (order-independent) and both walk the row sorted by x when re-placing. - Hoist the GHOST_SYSTEM_GAP = 80 constant declared locally in both ghost system placers to module scope. - Delete the constant-false isGhost plumbing in layoutMultipleSystems: keep ghost: false literals where they were set, drop the never-taken 'if (isGhost) le.ghost = true' branch. - Annotate the multi path's containers-only dimension block with #2513, the issue tracking that divergence. No behavior change. Refs #2512
This was referenced Aug 15, 2026
Merged
Code-review findings on this PR's diff: - makeLayoutNode: drop the conditional spreads that preserved each call site's accidental key-presence differences. Every consumer reads ghost and subLabel by truthiness (svg-renderer, drawio exporter, routing filters), no test asserts key absence, and exactOptionalPropertyTypes is off, so a uniform shape (subLabel plain, ghost always present with ?? false default) is observably identical while removing the per-node spread temps and the three-way ghost spelling. layout.test.ts's ghost toBe(false) pin on the multi path still holds via the default. - makeLayoutNode: owner becomes optional, removing the owner: undefined boilerplate at the two ghost call sites. - computeLayers: build nodeIds only in the topological fallback branch; on grouped / kind-tier-forced canvases the array was dead work. All 3691 core tests green; 168/168 example SVGs byte-identical vs main. Refs #2512
4 tasks
This branch was successfully deployed
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.
Summary
PR A of the #2512 layout.ts decomposition plan — the purely mechanical batch. Four commits, each independently green:
computeLayers/groupStartLayersOf— the layering phase (grouped bands → forced kind tiers → topological fallback → direction hints) and the group-title-gap map were textually identical betweenlayoutInnerandlayoutMultipleSystems; both now call one helper, so the two pipelines cannot drift on them (TPL-219, parallel-function parity).makeLayoutNode— the ten derivedLayoutNodefields were written out as five near-identical object literals (ghost users, ghost rows, single-system placement, ghost-system services, multi-system placement). One shared constructor; label/annotation/owner/ghost resolution stays at each call site. Conditional spread keepssubLabel/ghostkeys present only where the originals had them, so object shapes are unchanged.collapseAndAssignGroupLayersnamed options — 8 positional parameters with adjacent same-typed slots were the exact slot-swap hazard theLayoutOptionsdoc cites (Convert layout() tail to a LayoutOptions object (positional-param creep) [P2a follow-up] #1875). Also reattaches the function's JSDoc, orphaned 85 lines above it.centerRowsHorizontally(see proof below),GHOST_SYSTEM_GAPhoisted from two identical local declarations, constant-falseisGhostplumbing deleted (keptghost: falseliterals where they were set), and the multi path's containers-only dimension block annotated with fix(core): multi-system root view total dimensions ignore node and edge extents (potential clipping) #2513.All helpers stay module-private in
layout.ts; moving them into their own modules is PR D of the plan.Equivalence note for
centerRowsHorizontallyThe single-system block sorted the row ids by x before summing the row width; the multi-system block summed first and sorted after. The row width is a plain sum over the same id set (order-independent), and both variants walk the ids sorted by x when re-placing, so one canonical order (sort, then sum) reproduces both exactly.
Verification
pnpm --filter @karasu-tools/core test— 3691 tests, 132 files, all green after every commit (layout.test.ts asserts exact coordinates; no snapshots).pnpm typecheck/pnpm check:cycles/pnpm knip/pnpm lint/ format — all green.examples/**/*.krs(84 entries, with each project's.krs.styleapplied) rendered viabuildAllViewsSvgProjectin shape + icon modes onmainand on this branch — 168/168 SVGs byte-identical (diff -rclean).No changeset: internal refactor with zero user-visible change (per
.claude/rules/changesets.md).Refs #2512. Test perspective: TPL-219 (parallel-function parity).
🤖 Generated with Claude Code