fix(docs): make doc tree folders toggle open/closed#160
Merged
Conversation
Parent folders in the document tree could not be expanded/collapsed.
Root cause: a Svelte 5 reactivity bug. expandedIds is a $state Set and
the tree snippet reads it via {@const expanded = expandedIds.has(id)}.
The toggle handlers mutated the Set in place (expandedIds.add/delete)
and then reassigned the SAME reference (expandedIds = expandedIds). In
Svelte 5 this does NOT re-run {@const} reads, so the {#if expanded}
block never updated — clicks changed the Set but the UI stayed put.
Fix: use immutable updates everywhere expandedIds/childrenCache change
— build a new Set/Map and reassign the new reference. This reliably
triggers Svelte 5 to re-render the snippet.
Sites updated:
- toggleNode, expandPathToDoc, selectDoc (expandedIds)
- loadChildren (childrenCache)
Added a regression test (TreeRepro.svelte + set-reactivity.test) that
fails with the old in-place pattern and passes with the immutable one.
🔍 Cora AI Code Review🟡 Warning (1)
Review powered by cora-cli · BYOK · MIT |
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.
Problem
Parent folders in the document tree could not be expanded/collapsed. Clicking the chevron changed nothing.
Root cause — Svelte 5 reactivity bug
expandedIdsis a\$stateSetand the tree snippet reads it via{@const expanded = expandedIds.has(id)}. The toggle handlers mutated the Set in place (.add()/.delete()) and then reassigned the same reference (expandedIds = expandedIds). In Svelte 5 this does not re-run{@const}reads, so the{#if expanded}block never updated — the Set changed, the UI didn't.This is independent of the earlier
/doc/listlimit fix (#159). Even with full children loaded, the toggle was dead.Fix
Use immutable updates everywhere
expandedIds/childrenCachechange — build a newSet/Mapand reassign the new reference. Svelte 5 reliably re-renders the snippet on a reference change.Sites:
toggleNode,expandPathToDoc,selectDoc→expandedIds = new Set(...)loadChildren→childrenCache = new Map(...)Proof
Added a regression test (
TreeRepro.svelte+set-reactivity.test.ts) that reproduces the snippet pattern. It fails with the old in-place + same-ref reassign pattern and passes with the immutable update.Checks
vitest— 61 passed (incl. new regression test) ✅svelte-check— 0 errors ✅npm run build✅