Skip to content

Phase 1: Eliminate ephemeral nodes during editing #479

Closed

Description

@malibio

Goal

Remove ephemeral-during-editing behavior. Only ONE placeholder exists: on initial viewer load when parent has no children.

Problem

Current system allows ephemeral (non-persisted) nodes during editing, causing:

  • UNIQUE constraint violations
  • Complex deferred update queue (~700 lines)
  • Dependency tracking for ephemeral references
  • Race conditions and timing bugs

Solution

Blank nodes created during editing persist immediately (with 500ms debounce).

Only exception: Initial placeholder when BaseNodeViewer loads with no children.

Implementation Steps

1. Update ReactiveNodeService.createNode()

File: packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts

Remove automatic placeholder detection. Add isInitialPlaceholder flag parameter:

createNode(
  nodeData: Partial<Node>,
  isInitialPlaceholder: boolean = false
): string {
  // ...
  
  // Only skip persistence for initial viewer placeholder
  if (!isInitialPlaceholder) {
    sharedNodeStore.setNode(newNode, viewerSource);
  }
  // ...
}

2. Update BaseNodeViewer

File: packages/desktop-app/src/lib/design/components/base-node-viewer.svelte

Lines ~773-786: Pass true for initial placeholder only:

if (allNodes.length === 0) {
  const placeholderId = globalThis.crypto.randomUUID();
  viewerPlaceholder = nodeManager.createNode(
    {
      id: placeholderId,
      nodeType: 'text',
      content: '',
      parentId: null, // viewer-local
      // ...
    },
    true // isInitialPlaceholder = true
  );
}

All other node creation (Enter key, etc.): Pass false or omit (defaults to false).

3. Update Placeholder Detection Utility

File: packages/desktop-app/src/lib/utils/placeholder-detection.ts

Semantic change only - function stays the same, but now used for:

  • UI styling (gray text, etc.)
  • NOT for persistence decisions

Add comment clarifying new usage.

4. Update Tests

  • Remove tests expecting ephemeral during editing
  • Add tests for immediate persistence of blank nodes
  • Verify initial placeholder still works

Acceptance Criteria

  • Create blank node → persists after 500ms
  • Indent blank node → no UNIQUE/FOREIGN KEY errors
  • Initial viewer load (no children) → shows ONE placeholder
  • Reload viewer (with children) → NO placeholder
  • All existing tests pass
  • No regressions in user experience

Duration

4-6 hours

Risk

Medium - Changes fundamental behavior

Dependencies

None

Next Phase

Phase 2: Remove Deferred Update Queue

Activity

  1. self-assigned this
    on Nov 12, 2025
  2. malibio commented on Nov 12, 2025

    @malibio
    CollaboratorAuthor

    Test Baseline (before implementation)

    Date: 2025-11-12 15:31:32
    Branch: feature/issue-479-eliminate-ephemeral-nodes

    Test Results Summary:

    • ✅ 707 tests passing
    • ⏭️ 26 tests skipped (database integration tests)
    • ❌ 0 tests failing

    Detailed Status:

    • All unit tests passing (Happy-DOM environment)
    • Integration tests passing
    • Database persistence tests skipped (in-memory mode)
    • Regression prevention tests skipped

    Test Command: bun run test:all

    This baseline will be used to verify that the ephemeral node elimination does not introduce regressions.

  3. malibio commented on Nov 13, 2025

    @malibio
    CollaboratorAuthor

    Phase 1 Progress Update - Orphaned Node Bug Fixed

    Issue Discovered

    During testing, we found that blank text nodes with parentId: null were being created on page initialization, causing orphaned nodes in the database.

    Root Cause

    BaseNodeViewer has a reactive $effect() (line 1491-1522) that creates a placeholder when children drop to zero. This effect was:

    1. Setting parentId: null instead of parentId: nodeId
    2. Not passing isInitialPlaceholder: true flag, causing immediate persistence

    Fix Applied (Commit 2e5624b)

    Frontend Changes:

    • Fixed parentId: null → parentId: nodeId in reactive placeholder creation
    • Added isInitialPlaceholder: true to mark placeholder as ephemeral
    • Location: packages/desktop-app/src/lib/design/components/base-node-viewer.svelte:1491-1518

    Backend Changes:

    Testing Results

    ✅ No more orphaned nodes created - verified with database queries
    ✅ Correct parentId on new nodes - network inspection shows parentId: "2025-11-10"
    ✅ Backend accepts blank nodes - no more 500 errors for empty content
    ⚠️ UNIQUE constraint errors persist - expected, will be addressed in Phase 2

    Next Steps

    The UNIQUE constraint violations are the core issue Phase 1 is meant to solve. The orphaned node bug was a separate issue we discovered and fixed along the way.

  4. malibio commented on Nov 13, 2025

    @malibio
    CollaboratorAuthor

    ✅ Phase 1 Complete - Merged via PR #483

    All acceptance criteria met:

    • ✅ Create blank node → persists after 500ms debounce
    • ✅ Indent blank node → no UNIQUE/FOREIGN KEY errors
    • ✅ Initial viewer load (no children) → shows ONE placeholder
    • ✅ Reload viewer (with children) → NO placeholder
    • ✅ All 707 tests passing

    Implementation Summary:

    • Removed all isPlaceholder checks from persistence logic
    • Only ONE viewer-local placeholder exists (BaseNodeViewer when parent has no children)
    • All other blank nodes persist immediately
    • Simplified codebase: -195 lines, +180 lines (net -15 lines)

    Merge Commit: 0cdb9e5

    Ready for Phase 2: Remove Deferred Update Queue

  5. 5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions