Skip to content

Eliminate date-node-viewer onTitleChange callback effect - #697

Merged
malibio merged 3 commits into
mainfrom
feature/issue-694-eliminate-date-viewer-effect
Nov 30, 2025
Merged

malibio merged 3 commits into
mainfrom
feature/issue-694-eliminate-date-viewer-effect

Conversation

@malibio

@malibio malibio commented Nov 30, 2025

Copy link
Copy Markdown
Collaborator

Closes #694

Replace the "effect as event handler" anti-pattern in date-node-viewer.svelte
with parent-derived title in pane-content.svelte.

Changes:
- Remove $effect that calls onTitleChange callback in date-node-viewer
- Remove onTitleChange prop from date-node-viewer (no longer needed)
- Add $effect in pane-content that derives title from nodeId for date nodes
- Parent now uses formatDateTitle(parseDateString(nodeId)) directly

This follows the Svelte 5 best practice: parent components should derive
state from props rather than relying on child callbacks via effects.

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

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

malibio commented Nov 30, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Initial Review
PR #697: Eliminate date-node-viewer onTitleChange callback effect

Overall Assessment

This PR successfully eliminates the $effect anti-pattern in date-node-viewer.svelte by moving title derivation to the parent component (pane-content.svelte). The change correctly follows the Svelte 5 reactive pattern: parent derives values from props instead of relying on child callbacks for state synchronization.

The implementation is clean, well-documented, and achieves the intended architectural improvement.


Requirements Check (Issue #694)

Criterion Status
$effect eliminated from date-node-viewer.svelte ✅ Complete
Tab title still displays correctly for date nodes ✅ Verified via code analysis
Title updates when navigating between date nodes ✅ Handled by parent $effect watching activeTab.content.nodeId
Tests pass (bun run test:all) ✅ 1469 tests passed
Quality checks pass (bun run quality:fix) ✅ No issues

Code Review Findings

🟢 Positive Observations

  1. Proper anti-pattern elimination - The "effect as event handler" pattern has been correctly replaced with parent-derived state. The child component now has a single responsibility: rendering the date view and handling navigation.

  2. Clear documentation - The comment in date-node-viewer.svelte:23 explains why onTitleChange was removed, aiding future developers.

  3. Correct use of existing utilities - The implementation reuses parseDateString and formatDateTitle from the shared date-formatting module, following DRY principles.

  4. Minimal scope - Only 2 files changed with a net reduction of 15 lines. The change is atomic and focused.


🟡 Suggestions (Non-Blocking)

1. Consider consolidating date title update logic

pane-content.svelte:73-83

$effect(() => {
  if (activeTab?.content?.nodeType === 'date' && activeTab.content.nodeId) {
    const parsed = parseDateString(activeTab.content.nodeId);
    if (parsed) {
      const title = formatDateTitle(parsed);
      updateTabTitle(activeTab.id, title);
    }
  }
});

Observation: This effect runs on every activeTab change, not just for date nodes. While the guard clause prevents unnecessary updates, a future refactor could move this logic into a more centralized tab title management system that handles all node type-specific title formatting in one place.

[Nit]: Not a blocker - the current implementation is correct and efficient. Just noting for future architectural consideration when more node types need custom title handling.


2. NodeViewerProps interface still includes onTitleChange

/packages/desktop-app/src/lib/types/node-viewers.ts:16

onTitleChange?: (title: string) => void; // Callback when viewer wants to update its title

Observation: The onTitleChange prop is still defined in the shared interface. This is intentional because:

  • Other viewers (like BaseNodeViewer for text nodes) still use this callback pattern
  • Only date nodes derive their title from nodeId

This is NOT a problem - just confirming the design intent is understood. Different node types may legitimately have different title-derivation strategies.


Architecture Alignment

This change aligns with Svelte 5 best practices:

  • Unidirectional data flow: Parent owns the title state, child receives nodeId as prop
  • Derived over effects: Title is conceptually derivable from nodeId, so no callback needed
  • Separation of concerns: DateNodeViewer focuses on date display/navigation, parent handles tab metadata

Recommendation

✅ APPROVE

This is a clean, well-executed refactor that eliminates a known anti-pattern. The implementation is correct, tests pass, and the change improves code maintainability.


Reviewed by Principal Engineer AI Reviewer

…viewer

The previous implementation put date-specific logic in pane-content.svelte,
violating the plugin architecture where parent components should be type-agnostic.

Changes:
- Remove date-specific imports and logic from pane-content.svelte
- Remove isCustomViewer and shouldDisableTitleUpdates derived values
- Add onTitleChange prop back to date-node-viewer.svelte
- Call onTitleChange from navigateDate event handler (not effect)

This properly follows the event-driven pattern where type-specific viewers
call the generic onTitleChange callback when navigation occurs.

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

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

malibio commented Nov 30, 2025

Copy link
Copy Markdown
Collaborator Author

Re-Review Summary

Review Type: Re-Review (Post-Revision)
PR #697: Eliminate date-node-viewer onTitleChange callback effect
Reviewing Commit: 2c2e3d3 - Fix: Make pane-content type-agnostic, move title update to date-node-viewer


Context

The initial review approved commit bbc1847 which moved date title derivation to the parent (pane-content.svelte). However, this introduced a design flaw: it placed date-specific logic in a component that should be type-agnostic (following the plugin architecture).

Commit 2c2e3d3 correctly addresses this by:

  1. Removing all date-specific imports/logic from pane-content.svelte
  2. Restoring onTitleChange prop to date-node-viewer.svelte
  3. Calling onTitleChange from the navigateDate event handler (not an effect)

Requirements Check (Issue #694)

Criterion Status
$effect eliminated from date-node-viewer.svelte ✅ Complete - no $effect for title updates
Tab title still displays correctly for date nodes ✅ Verified - initial title set by NavigationService.generateTabTitle(), navigation updates via callback
Title updates when navigating between date nodes ✅ navigateDate() calls onTitleChange?.(formatDateTitle(normalizedDate))
Tests pass (bun run test:all) ✅ 1469 tests passed
Quality checks pass (bun run quality:fix) ✅ 0 errors, 0 warnings

Code Review Findings

🟢 Excellent Architectural Decision

The revised approach is architecturally superior to the initial implementation:

  1. Type-agnostic parent component - pane-content.svelte now has zero knowledge of specific node types. It simply passes onTitleChange and onNodeIdChange callbacks to whatever viewer is loaded. This adheres to the Open/Closed Principle: adding new node types requires no modification to the parent.

  2. Event-driven over effect-driven - The title update now happens in navigateDate() at lines 73-74:

    onNodeIdChange?.(newNodeId);
    onTitleChange?.(formatDateTitle(normalizedDate));

    This is the correct pattern - callbacks invoked from user actions, not reactive effects watching derived values.

  3. Clean separation of concerns:

    • NavigationService handles initial title generation (line 115: formatDateTitle(date))
    • DateNodeViewer handles title updates during navigation
    • pane-content.svelte remains a generic viewer router

🟢 Code Cleanup Verified

The removal of these derived values from pane-content.svelte is correct:

  • isCustomViewer - was only used for date-specific logic
  • shouldDisableTitleUpdates - no longer needed since viewers control their own title behavior

The disableTitleUpdates={true} prop on line 104 of date-node-viewer.svelte prevents BaseNodeViewer from overwriting the date title with content-based titles.


🟡 [Nit] Minor Whitespace Issue

/packages/desktop-app/src/lib/components/layout/pane-content.svelte:7

-  import type { Pane } from '$lib/stores/navigation.js';
-  
+  import type { Pane } from '$lib/stores/navigation.js';
+

The diff shows trailing whitespace was added on line 7 (the blank line after the import). This appears to be a formatting artifact. Not a blocker - should be caught by quality:fix on future commits.


Architecture Alignment

This implementation correctly follows the plugin architecture:

pane-content.svelte (type-agnostic router)
    |
    v passes generic callbacks
DateNodeViewer (type-specific viewer)
    |
    v calls onTitleChange from event handlers
NavigationService (handles title updates)

This is the proper inversion of control - the type-specific viewer decides when to update the title, the parent provides how via callback.


Recommendation

✅ APPROVE

This revision is a significant improvement over the initial approach. The code now:

  1. Eliminates the $effect anti-pattern as required
  2. Maintains proper architectural boundaries (type-agnostic parent)
  3. Uses event-driven callbacks correctly
  4. Passes all tests and quality checks

The change is ready to merge.


Re-reviewed by Principal Engineer AI Reviewer

Fixed minor formatting issue flagged in code review:
- Removed trailing whitespace on blank line 7

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

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

malibio commented Nov 30, 2025

Copy link
Copy Markdown
Collaborator Author

Review Recommendations Addressed

Summary

Category Action
✅ Addressed 1 recommendation
⏭️ Skipped 2 recommendations (intentional design / future considerations)

Changes Made

🟢 Nitpick: Trailing whitespace (FIXED)

  • pane-content.svelte:7 - Removed trailing whitespace on blank line
  • Commit: b671c64

Recommendations Skipped (with justification)

1. Consolidating date title update logic (Initial Review)

  • Status: Skipped
  • Reason: The re-review confirmed the current architecture is correct. The date-specific logic is now properly encapsulated in DateNodeViewer, keeping pane-content.svelte type-agnostic. This suggestion was for "future architectural consideration" and is not applicable after the second commit fixed the design.

2. NodeViewerProps interface includes onTitleChange (Initial Review)

  • Status: Skipped
  • Reason: Confirmed as intentional design. Different node types have different title-derivation strategies - onTitleChange callback is still used by other viewers (like BaseNodeViewer for text nodes), only date nodes derive title from nodeId.

Verification

@malibio
malibio merged commit 3462429 into main Nov 30, 2025
@malibio
malibio deleted the feature/issue-694-eliminate-date-viewer-effect branch November 30, 2025 21:44
malibio added a commit that referenced this pull request Feb 4, 2026
* Eliminate date-node-viewer onTitleChange callback effect (#694)

Replace the "effect as event handler" anti-pattern in date-node-viewer.svelte
with parent-derived title in pane-content.svelte.

Changes:
- Remove $effect that calls onTitleChange callback in date-node-viewer
- Remove onTitleChange prop from date-node-viewer (no longer needed)
- Add $effect in pane-content that derives title from nodeId for date nodes
- Parent now uses formatDateTitle(parseDateString(nodeId)) directly

This follows the Svelte 5 best practice: parent components should derive
state from props rather than relying on child callbacks via effects.

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

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

* Fix: Make pane-content type-agnostic, move title update to date-node-viewer

The previous implementation put date-specific logic in pane-content.svelte,
violating the plugin architecture where parent components should be type-agnostic.

Changes:
- Remove date-specific imports and logic from pane-content.svelte
- Remove isCustomViewer and shouldDisableTitleUpdates derived values
- Add onTitleChange prop back to date-node-viewer.svelte
- Call onTitleChange from navigateDate event handler (not effect)

This properly follows the event-driven pattern where type-specific viewers
call the generic onTitleChange callback when navigation occurs.

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

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

* Address review: Remove trailing whitespace in pane-content.svelte

Fixed minor formatting issue flagged in code review:
- Removed trailing whitespace on blank line 7

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

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

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* Eliminate date-node-viewer onTitleChange callback effect (#694)

Replace the "effect as event handler" anti-pattern in date-node-viewer.svelte
with parent-derived title in pane-content.svelte.

Changes:
- Remove $effect that calls onTitleChange callback in date-node-viewer
- Remove onTitleChange prop from date-node-viewer (no longer needed)
- Add $effect in pane-content that derives title from nodeId for date nodes
- Parent now uses formatDateTitle(parseDateString(nodeId)) directly

This follows the Svelte 5 best practice: parent components should derive
state from props rather than relying on child callbacks via effects.

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

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

* Fix: Make pane-content type-agnostic, move title update to date-node-viewer

The previous implementation put date-specific logic in pane-content.svelte,
violating the plugin architecture where parent components should be type-agnostic.

Changes:
- Remove date-specific imports and logic from pane-content.svelte
- Remove isCustomViewer and shouldDisableTitleUpdates derived values
- Add onTitleChange prop back to date-node-viewer.svelte
- Call onTitleChange from navigateDate event handler (not effect)

This properly follows the event-driven pattern where type-specific viewers
call the generic onTitleChange callback when navigation occurs.

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

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

* Address review: Remove trailing whitespace in pane-content.svelte

Fixed minor formatting issue flagged in code review:
- Removed trailing whitespace on blank line 7

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

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

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Eliminate date-node-viewer onTitleChange callback effect (#694)

Replace the "effect as event handler" anti-pattern in date-node-viewer.svelte
with parent-derived title in pane-content.svelte.

Changes:
- Remove $effect that calls onTitleChange callback in date-node-viewer
- Remove onTitleChange prop from date-node-viewer (no longer needed)
- Add $effect in pane-content that derives title from nodeId for date nodes
- Parent now uses formatDateTitle(parseDateString(nodeId)) directly

This follows the Svelte 5 best practice: parent components should derive
state from props rather than relying on child callbacks via effects.

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

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

* Fix: Make pane-content type-agnostic, move title update to date-node-viewer

The previous implementation put date-specific logic in pane-content.svelte,
violating the plugin architecture where parent components should be type-agnostic.

Changes:
- Remove date-specific imports and logic from pane-content.svelte
- Remove isCustomViewer and shouldDisableTitleUpdates derived values
- Add onTitleChange prop back to date-node-viewer.svelte
- Call onTitleChange from navigateDate event handler (not effect)

This properly follows the event-driven pattern where type-specific viewers
call the generic onTitleChange callback when navigation occurs.

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

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

* Address review: Remove trailing whitespace in pane-content.svelte

Fixed minor formatting issue flagged in code review:
- Removed trailing whitespace on blank line 7

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

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

---------

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.

Eliminate date-node-viewer onTitleChange callback effect

1 participant