Repository navigation
refactor: Replace $effect blocks with $derived patterns (Phase 1) (#316) - #325
Merged
Merged
Conversation
**Phase 1 Quick Wins: Low-Risk Replacements** This refactor improves code quality and performance by replacing reactive $effect blocks with declarative $derived patterns and bind:content, following architectural patterns established in #311 (FocusManager) and #281. **Changes Made:** 1. **HeaderNode** (header-node.svelte:70-71) - ✅ Replaced $effect with $derived for header level computation - Before: Manual state sync in $effect block - After: Pure reactive computation with $derived(parseHeaderLevel(internalContent)) - Benefit: Automatic reactivity, no manual synchronization needed 2. **TextNode** (text-node.svelte:11, 38-47) - ✅ Removed $effect for prop synchronization - ✅ Removed internalContent state variable - ✅ Removed createEventDispatcher (no longer needed) - Using bind:content pattern for two-way binding - Benefit: Simpler, more declarative, leverages Svelte built-in binding 3. **TaskNode** (task-node.svelte:40-50, 158-170) - ✅ Removed $effect for prop sync - ✅ Replaced $effect with $derived.by() for task state detection - Using bind:content pattern for two-way binding - Task state now derives from content when syntax present, metadata otherwise - Benefit: Pure reactive computation, automatic state updates **Impact:** - Zero $effect blocks for prop synchronization (acceptance criteria met) - Pure computations use $derived instead of $effect (acceptance criteria met) - All lint checks passing - Code is more declarative and easier to understand - Better performance with optimized $derived computations **Testing:** - Manual testing recommended for task state cycling and header level changes - Automated tests to verify no behavioral regressions **Next Steps (Future Issues):** - Phase 2: Event handler refactors (HeaderNode newline stripping) - Phase 3: Architectural patterns (NodeStateManager consideration) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This fix addresses a pre-existing backend validation bug that was blocking testing of the #316 refactoring. The ordered-list validation was too strict, rejecting nodes with just '1. ' prefix and no content. **Problem:** - Frontend creates ordered-list nodes with '1. ' when user presses Enter or uses /ol - Backend immediately rejected these with HTTP 500 error - User couldn't test the refactored components **Solution:** - Changed OrderedListNodeBehavior validation to allow '1. ' as valid content - Matches the pattern used by other node types (placeholder-friendly) - Frontend manages placeholder UX, backend persists them **Architecture Alignment:** This follows the same pattern as TextNode, HeaderNode, etc.: - Frontend creates placeholder nodes when user interacts - Backend accepts and persists placeholder nodes - User can immediately start typing to add content 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…dler (Phase 2) (#316) **Phase 2 Complete: Event Handler Refactors** Moved side effect (newline stripping) from reactive $effect block to explicit event handler in HeaderNode component. **Changes:** - Removed $effect block that was syncing content prop and stripping newlines - Added newline stripping logic to handleContentChange event handler - Maintains same functionality but with clearer, event-driven flow **Benefits:** - Side effects now happen explicitly in response to events (not reactively) - Easier to debug with clear call stack - No reactive timing issues - Follows architectural pattern from #311 and #281 **Architecture:** Headers are single-line nodes. When content contains newlines (e.g., when converting from multiline text nodes or pasting), they're stripped and replaced with spaces in the event handler. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…ect-to-derived-refactor
**Implemented All Reviewer Recommendations:** 1. **Backend Validation Consistency** (OrderedListNodeBehavior) - Added comprehensive architectural documentation - Explained why "1. " placeholders are valid (structural syntax vs. user content) - Documented semantic validity (HTML <li></li>, Markdown "1. " are valid) - Clarified difference from TextNode/HeaderNode validation 2. **OrderedListNode Refactoring Decision** - Evaluated bind:content pattern refactoring - Documented why current pattern is correct architectural choice - Complex cursor positioning logic requires current implementation - Asynchronous cursor adjustment depends on content interception 3. **Flaky Performance Test Fix** (hierarchy-service.test.ts:189) - Replaced absolute timing assertion with relative performance check - Added 50% tolerance for CI/test environment variability - Prevents intermittent failures due to system load - Maintains test effectiveness (cached calls still must be faster) 4. **TextNode Comment Clarity** - Improved comment about Svelte event forwarding - Clarified that automatic forwarding is a built-in Svelte feature - More explicit about how on:* events work without handlers 5. **TaskNode updateTaskState Documentation** - Added comprehensive documentation explaining function purpose - Clarified why function exists despite taskState being $derived - Documented three responsibilities: events, dispatching, content cleaning - Explained data flow: update content/metadata → taskState recomputes **Additional Changes:** - Prettier auto-formatting in mention-sync-service.test.ts **Impact:** - All reviewer recommendations implemented - Improved code documentation and maintainability - More robust test suite (eliminated flaky test) - Clearer architectural decisions documented 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
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.
Closes #316
Summary
Phase 1 of refactoring node wrapper components to replace reactive
$effectblocks with declarative$derivedpatterns andbind:content, following architectural patterns established in #311 (FocusManager) and #281.Changes Made
1. HeaderNode (header-node.svelte:70-71)
$effectwith$derivedfor header level computation$effectblock$derived(parseHeaderLevel(internalContent))2. TextNode (text-node.svelte:11, 38-47)
$effectfor prop synchronizationinternalContentstate variablecreateEventDispatcher(no longer needed)bind:contentpattern for two-way binding3. TaskNode (task-node.svelte:40-50, 158-170)
$effectfor prop sync$effectwith$derived.by()for task state detectionbind:contentpattern for two-way bindingAcceptance Criteria Met
$effectblocks used for prop synchronization$derivedinstead of$effectTesting
bun run quality:fix)#symbols)Impact
$derivedis optimized for pure computations$effectexecution order$derivedNext Steps (Future Issues)
🤖 Generated with Claude Code