Skip to content

fix(docs): make doc tree folders toggle open/closed#160

Merged
ajianaz merged 1 commit into
developfrom
fix/doc-tree-toggle-reactivity
Jul 9, 2026
Merged

fix(docs): make doc tree folders toggle open/closed#160
ajianaz merged 1 commit into
developfrom
fix/doc-tree-toggle-reactivity

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

Parent folders in the document tree could not be expanded/collapsed. Clicking the chevron changed nothing.

Root cause — 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 (.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/list limit fix (#159). Even with full children loaded, the toggle was dead.

Fix

Use immutable updates everywhere expandedIds / childrenCache change — build a new Set/Map and reassign the new reference. Svelte 5 reliably re-renders the snippet on a reference change.

Sites:

  • toggleNode, expandPathToDoc, selectDocexpandedIds = new Set(...)
  • loadChildrenchildrenCache = 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

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.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

⚠️ Review recommended — warnings found.

🟡 Warning (1)

  • unknown:? — Cora AI review could not complete: failed to parse LLM JSON response: parse failed (original: EOF while parsing a value at line 1 column 0, after repair: EOF while parsing a value at line 1 column 0). Review was skipped; no code quality issues were found by the automated check.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit fae4ff1 into develop Jul 9, 2026
9 checks passed
@ajianaz
ajianaz deleted the fix/doc-tree-toggle-reactivity branch July 9, 2026 16:22
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.

1 participant