fix(tree-renderer): handle range→non-range transitions in deepMergeTreeNodes#16
fix(tree-renderer): handle range→non-range transitions in deepMergeTreeNodes#16
Conversation
…eeNodes When a tree node transitions from having a range structure (d and s arrays) to a non-range structure (e.g., an else clause), the old merge behavior would preserve the old `d` array because it only updated keys present in the update object. This caused bugs where the renderer would iterate over old range items using new statics, resulting in incorrect content like: - "No posts found matching [POST_TITLE_1]" - "No posts found matching [POST_TITLE_2]" Instead of a single correct message: - "No posts found matching [SEARCH_QUERY]" The fix detects range→non-range transitions and returns the update directly instead of merging, ensuring the old range data is fully replaced. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ReviewLooks good overall! The fix correctly handles the range→non-range transition bug. The root cause analysis is clear and the solution is appropriate. Key strengths:
Minor suggestions:
Recommendation: Approve with optional improvements above. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the tree renderer where transitioning from a range structure (list items) to a non-range structure (else clause) incorrectly preserved old range items, causing the renderer to display wrong content with outdated data.
Key Changes:
- Added range-to-non-range transition detection in
deepMergeTreeNodesto replace instead of merge when appropriate - Introduced comprehensive test suite covering state transitions and rendering behavior for range structures
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
state/tree-renderer.ts |
Implements range→non-range transition detection by checking if existing node has range structure (d and s arrays) while update doesn't, triggering full replacement instead of merge to prevent stale data preservation |
tests/tree-renderer.test.ts |
Adds comprehensive test coverage for range transitions including basic range-to-non-range replacement, range-to-range preservation, nested transitions, and HTML rendering validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Extract isRangeNode() type guard function with documentation - Add null/object type check for stricter validation - Add comprehensive JSDoc explaining range vs non-range structures - Add documentation header to test file explaining the concepts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Review ✅Summary: Clean fix for the range→non-range transition bug. The implementation correctly detects structural mismatches and replaces instead of merging. Strengths:
Minor observations:
Security/Bugs: None identified. The null checks in isRangeNode() prevent runtime errors. LGTM - ready to merge once tests pass. |
Summary
deepMergeTreeNodesmerges an update, if existing node hasd(range items) but update doesn't, the olddwas preservedProblem
When searching for non-existent terms in a list view:
Instead of:
Root Cause
In
deepMergeTreeNodes:Fix
Detect range→non-range transition and replace instead of merge:
Test plan
deepMergeTreeNodesrange→non-range transitions🤖 Generated with Claude Code