Skip to content

Consolidate Dual Node Store Architecture - Eliminate nodeData in Favor of sharedNodeStore - #682

Merged
malibio merged 1 commit into
mainfrom
feature/issue-679-consolidate-node-stores
Nov 29, 2025
Merged

malibio merged 1 commit into
mainfrom
feature/issue-679-consolidate-node-stores

Conversation

@malibio

@malibio malibio commented Nov 28, 2025

Copy link
Copy Markdown
Collaborator

Closes #679

)

## Summary
- Converted sharedNodeStore to Svelte 5 $state for automatic reactivity
- Migrated TextNode, DateNode from nodeData to sharedNodeStore
- Updated OptimisticOperationManager to use sharedNodeStore
- Removed deprecated reactive-node-data.svelte.ts (and its tests)
- Removed viewedNodeCache workaround (no longer needed with $state)
- Updated all imports to use .svelte.ts extension

## Changes
- `sharedNodeStore.nodes` now uses `$state(new Map<string, Node>())`
- Added `snapshot()` and `restore()` methods for optimistic rollback
- Components using `$derived(sharedNodeStore.getNode(nodeId))` now
  automatically re-render when nodes change (cross-pane reactivity)

## Test Results
- Frontend: 74 test files, 1469 tests passed (24 tests removed with deleted file)
- Backend: 516 passed, 0 failed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Nov 28, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #682 - Consolidate Dual Node Store Architecture

Review Type

Initial Review (No prior reviews detected)

Summary

This PR successfully addresses Issue #679 by consolidating the dual node store architecture into a single sharedNodeStore as the source of truth. The implementation:

  1. Converts sharedNodeStore to use Svelte 5 $state for automatic reactivity
  2. Migrates all components from nodeData to sharedNodeStore
  3. Adds snapshot/restore methods to sharedNodeStore for optimistic rollback
  4. Removes reactive-node-data.svelte.ts entirely (421 lines deleted)
  5. Removes viewedNodeCache workaround from base-node-viewer.svelte
  6. Updates all tests to use the consolidated store

The change results in a net reduction of ~994 lines of code while improving cross-pane reactivity.


Requirements Validation

Acceptance Criterion Status
sharedNodeStore converted to use Svelte 5 `$state` for nodes Map ✅ Line 362: `nodes = $state(new Map<string, Node>())`
sharedNodeStore file renamed to `.svelte.ts` ✅ `shared-node-store.ts` → `shared-node-store.svelte.ts`
viewedNodeCache workaround removed from base-node-viewer.svelte ✅ Removed, now uses `$derived` directly
All node components use sharedNodeStore.getNode() exclusively ✅
text-node.svelte migrated to sharedNodeStore ✅
date-node.svelte migrated to sharedNodeStore ✅
base-node-viewer.svelte no longer imports reactiveNodeData ✅
sharedNodeStore has snapshot/restore methods ✅ Lines 2186-2212
OptimisticOperationManager uses sharedNodeStore for snapshots ✅
reactive-node-data.svelte.ts deleted ✅
All related tests updated and passing ✅ 1469 tests pass

Findings

Critical Issues

None identified.

The implementation correctly addresses the architectural problem of having two unsynchronized stores. The Svelte 5 $state reactivity is properly applied, and all component migrations follow the established pattern.


Suggested Improvements

1. [Improvement] Document test helper method visibility

📁 packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:2279

The __resetForTesting() method is appropriately prefixed with __ to indicate internal use. Consider adding a @internal JSDoc tag for consistency with snapshot() and restore() methods.

/**
 * Reset store state (for testing only)
 * @internal
 */
__resetForTesting(): void {

Rationale: Documentation consistency helps future maintainers understand API boundaries (DRY principle for documentation).


2. [Improvement] Consider extracting SimplePersistenceCoordinator

📁 packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:54-245

The SimplePersistenceCoordinator class (~190 lines) is a substantial utility embedded in the store file. Consider extracting it to a separate file for better separation of concerns.

Rationale: Single Responsibility Principle - the store file is already 2300+ lines. This extraction would improve maintainability without changing functionality.

Status: This is non-blocking as the current implementation is correct and well-documented.


Nitpicks

Nit: Test import consistency

📁 packages/desktop-app/src/tests/services/optimistic-operation-manager.test.ts:18

The import path uses the new .svelte.ts extension correctly. Good attention to detail in updating all test imports.


Architecture Assessment

Positive Changes

  1. Single Source of Truth: The consolidation eliminates the race condition where nodeData could become stale because it wasn't receiving updates from sharedNodeStore.

  2. Proper Reactivity: Using $state(new Map<string, Node>()) enables Svelte 5's fine-grained reactivity, so $derived(sharedNodeStore.getNode(nodeId)) will properly re-run when nodes change.

  3. Clean Migration: Components now use a consistent pattern:

    let node = $derived(sharedNodeStore.getNode(nodeId));
  4. Preserved Functionality: The snapshot() and restore() methods maintain optimistic update rollback capability that was previously in nodeData.

  5. Test Coverage Maintained: All 1469 tests pass, demonstrating the refactor preserves expected behavior.

Risk Assessment

Low Risk: This is a consolidation refactor that removes redundant code while preserving existing interfaces. The changes are straightforward import path updates and the addition of $state wrapper.


Test Results

Test Files  74 passed (74)
     Tests  1469 passed (1469)
  Duration  8.79s

All tests pass. The deleted reactive-node-data.test.ts (614 lines) tested functionality now handled by shared-node-store.test.ts.


Recommendation

APPROVE ✅

This PR successfully consolidates the dual store architecture into a single source of truth with proper Svelte 5 reactivity. The implementation:

  • Meets all acceptance criteria
  • Reduces code complexity (net -994 lines)
  • Maintains full test coverage
  • Follows established patterns
  • Contains no security issues

The suggested improvements are optional and can be addressed in future iterations.


🤖 Generated with Claude Code

@malibio

malibio commented Nov 28, 2025

Copy link
Copy Markdown
Collaborator Author

Review Recommendations - Addressed

Summary

Recommendation Status Notes
Add @internal JSDoc tag to __resetForTesting() ✅ Already present Found at line 2277 - no changes needed
Extract SimplePersistenceCoordinator ⏭️ Skipped Reviewer marked as non-blocking; extracting would be scope creep for this consolidation PR

Quality Checks

  • ✅ svelte-check: 0 errors, 0 warnings
  • ✅ eslint: Passed
  • ✅ cargo fmt: Passed
  • ✅ cargo clippy: Passed

Conclusion

No code changes required. The @internal tag was already in place, and the extraction suggestion is deferred for a future PR focused on store modularization.


🤖 Generated with Claude Code

@malibio
malibio merged commit 4fb99fb into main Nov 29, 2025
@malibio
malibio deleted the feature/issue-679-consolidate-node-stores branch November 29, 2025 11:51
malibio added a commit that referenced this pull request Feb 4, 2026
) (#682)

## Summary
- Converted sharedNodeStore to Svelte 5 $state for automatic reactivity
- Migrated TextNode, DateNode from nodeData to sharedNodeStore
- Updated OptimisticOperationManager to use sharedNodeStore
- Removed deprecated reactive-node-data.svelte.ts (and its tests)
- Removed viewedNodeCache workaround (no longer needed with $state)
- Updated all imports to use .svelte.ts extension

## Changes
- `sharedNodeStore.nodes` now uses `$state(new Map<string, Node>())`
- Added `snapshot()` and `restore()` methods for optimistic rollback
- Components using `$derived(sharedNodeStore.getNode(nodeId))` now
  automatically re-render when nodes change (cross-pane reactivity)

## Test Results
- Frontend: 74 test files, 1469 tests passed (24 tests removed with deleted file)
- Backend: 516 passed, 0 failed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
) (#682)

## Summary
- Converted sharedNodeStore to Svelte 5 $state for automatic reactivity
- Migrated TextNode, DateNode from nodeData to sharedNodeStore
- Updated OptimisticOperationManager to use sharedNodeStore
- Removed deprecated reactive-node-data.svelte.ts (and its tests)
- Removed viewedNodeCache workaround (no longer needed with $state)
- Updated all imports to use .svelte.ts extension

## Changes
- `sharedNodeStore.nodes` now uses `$state(new Map<string, Node>())`
- Added `snapshot()` and `restore()` methods for optimistic rollback
- Components using `$derived(sharedNodeStore.getNode(nodeId))` now
  automatically re-render when nodes change (cross-pane reactivity)

## Test Results
- Frontend: 74 test files, 1469 tests passed (24 tests removed with deleted file)
- Backend: 516 passed, 0 failed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
) (#682)

## Summary
- Converted sharedNodeStore to Svelte 5 $state for automatic reactivity
- Migrated TextNode, DateNode from nodeData to sharedNodeStore
- Updated OptimisticOperationManager to use sharedNodeStore
- Removed deprecated reactive-node-data.svelte.ts (and its tests)
- Removed viewedNodeCache workaround (no longer needed with $state)
- Updated all imports to use .svelte.ts extension

## Changes
- `sharedNodeStore.nodes` now uses `$state(new Map<string, Node>())`
- Added `snapshot()` and `restore()` methods for optimistic rollback
- Components using `$derived(sharedNodeStore.getNode(nodeId))` now
  automatically re-render when nodes change (cross-pane reactivity)

## Test Results
- Frontend: 74 test files, 1469 tests passed (24 tests removed with deleted file)
- Backend: 516 passed, 0 failed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
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.

Consolidate Dual Node Store Architecture - Eliminate nodeData in Favor of sharedNodeStore

1 participant