Skip to content

Split the base-node-viewer god-component - #1577

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1518-split-base-node-viewer
Jul 7, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1518-split-base-node-viewer

Conversation

@malibio

@malibio malibio commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #1518

base-node-viewer.svelte was ~2237 lines mixing collection management,
viewer-local hydration, header handling, placeholder-promotion reactivity,
schema-form loading, component loading, and per-row rendering. Two problems
dominated its size: scattered pure helpers inline in the script, and ~450
lines of near-duplicated template — every node row rendered twice (plugin
component branch + BaseNode fallback branch) with nearly identical inline
event handlers.

Extract the row rendering into node-row.svelte, which renders the
plugin-vs-fallback branch once and re-exposes the node events to the viewer
as callback props. The handler bodies move up into the viewer as single named
methods. Extract the pure/stateless concerns (cursor utils, schema-field
update, fallback content/metadata, node-type predicate) into plain .ts
siblings, and the two reactive component loaders into .svelte.ts store-classes.

Consolidate the core-node-type predicate that had drifted into a private twin
in navigation-service into one shared node-type-predicates module.

Reconcile a latent inconsistency: the fallback branch's nodeTypeChanged
promoted a placeholder synchronously while every other promotion path defers
via tick() and gates on isPromoting. The unified handler uses the
tick-deferred, isPromoting-guarded path, removing the state_unsafe_mutation
risk the sync path carried. Also drop the dead write-only expandedState map
(a #580-transition leftover nothing read).

Viewer drops from ~2237 to ~1526 lines; behavior unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@malibio

malibio commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

🔍 Pragmatic Code Review — PR #1577 (Split base-node-viewer god-component, #1518)

Review Type: Initial Review
Reviewer: Principal Engineer AI (Pragmatic Quality framework)

Note: posted as a comment, not a formal approval — this PR was authored in the same session, so self-approval is disallowed. The merge decision is the human author's.


Requirements Check

Acceptance Criterion Status
base-node-viewer split into focused units; behavior unchanged ✅ Met
Code passes bun run quality:fix; tests pass ✅ Met (see notes)

📝 Notes

  • Viewer shrinks 2237 → 1526 LOC (−32%). The ~450-line duplicated per-row template (plugin-component branch + BaseNode fallback branch, each with ~11 near-identical inline handlers) collapses into a single node-row.svelte (328 LOC) plus one set of named viewer handlers.
  • Concerns split into 8 focused siblings: node-row.svelte, node-row-types.ts, node-type-predicates.ts, viewer-cursor-utils.ts, schema-field-update.ts, fallback-node-render.ts, node-component-loader.svelte.ts, schema-form-loader.svelte.ts.
  • quality:fix: the frontend portion (eslint --fix + svelte-check) is clean — 0 errors / 0 warnings across 1729 files. The rust:quality:fix stage was not re-run to completion here because the change is frontend-only and it initially tripped the known fresh-worktree missing-sidecar build error (unrelated to this diff); the sidecar was restored and the pre-push gate (test:all + cargo build nodespaced + full e2e) passed end-to-end, which covers the Rust build.
  • Tests: full unit suite 3943 passed, no new failures vs baseline (the one failing architecture-benchmarks perf test is a pre-existing timing-flake, unrelated). 90 real-browser interaction tests pass (enter-key-focus, backspace-focus, slash-dropdown, focus-management, rapid-keyboard) — these drive the exact refactored code paths in Chromium.

Code Review Findings

Overall this is a clean, disciplined extraction. Behavior is preserved except for two intentional changes (the nodeTypeChanged reconciliation and the dead-expandedState removal), both verified below. No 🔴 critical issues.

🟢 Verified correct — behavior preservation

  • Event forwarding (node-row.svelte:100-160): all 11 events are re-forwarded in both the plugin and fallback branches. The 4 node-context events (contentChanged, nodeTypeChanged, slashCommandSelected, taskStateChanged) call onX(node, e.detail); the other 7 call onX(e.detail). These match the (_node, _detail) vs (_detail) signatures in node-row-types.ts:83-95 and the viewer handler defs exactly. A mismatch here would be a svelte-check type error — and svelte-check is clean.
  • Placeholder promotion (base-node-viewer.svelte:965,1040,1161): each tick().then() closure captures const promotionParentId = nodeId before deferral and uses it as parentId. This is a small robustness improvement over the original (which read the mutable nodeId prop inside the deferred closure). resetPlaceholderId() + isPromoting sequencing matches the original in all three paths.
  • updateSchemaField / extractNodeMetadata (schema-field-update.ts): now import sharedNodeStore / pluginRegistry directly instead of receiving them via closure. Both are module singletons, so this is equivalent; viewerId is passed as a param. Logic is byte-equivalent to the original.
  • Fallback render helpers (fallback-node-render.ts): extractFallbackDisplayContent / extractFallbackMetadata / normalizeCodeBlockContent moved verbatim.
  • Cursor utils (viewer-cursor-utils.ts): saveCursorPosition / restoreCursorPosition / getTextNodes moved verbatim; correctly distinguished from the click-mapping cursor-positioning.ts (no duplication).

🟢 Verified correct — intentional changes

  • nodeTypeChanged reconciliation (base-node-viewer.svelte:995-1093): the old fallback branch promoted a placeholder synchronously (no tick(), no isPromoting guard) while the plugin branch had no placeholder path at all — a latent drift that risked state_unsafe_mutation. The unified handleNodeTypeChanged now uses the same tick()-deferred + isPromoting-guarded path as contentChanged / slashCommandSelected. This is the correct, consistent target and was approved.
  • Dead expandedState removal: confirmed the map was write-only in the original — handleToggleExpanded computed currentState only to write !currentState back, and nothing in the render path or any $derived ever read expandedState (the flatten reads uiState.expanded from nodeManager). The real toggle still routes through nodeManager.toggleExpanded(). Safe to delete.

🟢 Verified correct — CSS move

  • .node-content-wrapper, .chevron-icon, .custom-entity-open-button, and the header-level :has() rules moved into node-row.svelte; .node-container (the margin-left indent) correctly stayed in the viewer. DOM nesting is NodeRow → .node-container → .node-content-area → .base-node-viewer, so the chevron's --node-indent / --circle-offset (declared on .base-node-viewer) still cascade down. No rule dropped or duplicated.

🟢 Dedup

  • navigation-service.ts: the private CORE_NODE_TYPES / isCustomSchemaNodeType twin is deleted and replaced with an import of the shared isCustomSchemaType from node-type-predicates.ts; both call sites renamed. Good — removes a real drift hazard.

🟢 Standards

  • No lint suppression, no any, no raw console.* in the new files; createLogger used where logging occurs. New code comments describe behavior directly; the only issue-number references (#653, #681, #580, #709, #965, #1564, #1470) are moved verbatim from the original source and sit in code (not docs), which is consistent with the surrounding file.

🟡 Minor (non-blocking) — optional follow-ups

  • node-row.svelte is styling-heavy (~150 of 328 lines are the migrated chevron/header-level CSS). That's inherent to moving the per-row styles with the per-row markup and is fine. No action needed.
  • taskStateChanged on the fallback <BaseNode> branch (node-row.svelte:156) remains a dead binding (plain BaseNode never dispatches it; only task-node.svelte does). This is preserved from the original and harmless — worth a one-line comment someday, but not in scope.
  • nodeManager.toggleExpanded return value: handleToggleExpanded no longer inspects any local expand state; behavior now relies entirely on nodeManager. Confirmed this is the actual source of truth the render path reads, so correct — just flagging that the viewer-local expand state is fully gone (intended).

Recommendation: APPROVE (assessment)

A well-scoped, low-risk refactor that meets both acceptance criteria. The duplication is genuinely eliminated (not merely relocated), the one behavioral reconciliation is an improvement that removes a state_unsafe_mutation risk, and the dead-code removal is verified safe. Type-checking, the full unit suite, real-browser interaction tests, and the pre-push e2e gate all pass. No changes required before merge.

Merge remains the human author's call.

The pragmatic review noted the on:taskStateChanged binding on the plain
BaseNode fallback branch is inert (only task-node.svelte dispatches that
event), so it fires only via the plugin-component branch. Add a comment
so a future reader doesn't mistake it for a live path. Kept for branch
symmetry — no behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@malibio

malibio commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

✅ Address-review summary

The review returned APPROVE with no 🔴 critical and no blocking 🟡 findings — the three 🟡 items were explicitly marked "no action needed / not in scope / intended."

Addressed (1):

  • 🟢 Documented the inert on:taskStateChanged binding on the plain-BaseNode fallback branch (node-row.svelte) — a comment so future readers don't mistake it for a live path. Comment-only, no behavior change. (commit c1702226)

Skipped (2), with reasoning:

  • ⏭️ "node-row.svelte is styling-heavy" — reviewer stated "inherent and fine, no action needed." Splitting the per-row CSS from its per-row markup would fragment for no benefit.
  • ⏭️ "expand state fully gone (intended)" — reviewer confirmed correct and intended; nothing to change.

Verification: svelte-check clean (0 errors / 0 warnings, 1729 files). Change is comment-only, so no logic re-test needed; the pre-push gate (test:all + cargo build + full e2e) passed on push.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The only change since the review is a one-line clarifying comment with zero logic impact. No critical/important issues were addressed, no functionality changed, no refactoring performed. The PR is ready for merge (pending the author's decision).

@malibio
malibio merged commit 7a9114b into main Jul 7, 2026
2 checks passed
@malibio
malibio deleted the worktree-issue-1518-split-base-node-viewer branch July 7, 2026 10:33
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.

Split the base-node-viewer god-component

1 participant