Skip to content

Commit c1a34b1

Browse files
jaysin586claude
andcommitted
fix(docs-layout): untrack headings write too, same self-cycle risk
The headings $effect had the same shape as the breadcrumb effect: it writes `headings = extractHeadings(contentElement)` from inside an `$effect`, and Svelte 5's `$state` assignment reads the current value to dedupe equal writes. That hidden read would subscribe the effect to its own write and re-fire on every doc page. Same `untrack` fix. Compute `next` outside, write inside `untrack`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f000296 commit c1a34b1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/lib/components/DocsLayoutV2.svelte‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@
183183
let headings: TocHeading[] = $state([])
184184
185185
const refreshHeadings = () => {
186-
if (contentElement) headings = extractHeadings(contentElement)
186+
if (!contentElement) return
187+
const next = extractHeadings(contentElement)
188+
// Untracked to avoid the same self-cycle the breadcrumb effect can hit:
189+
// assignment to a `$state` reads the existing value to dedupe, and that
190+
// read inside an `$effect` would subscribe the effect to its own write.
191+
untrack(() => {
192+
headings = next
193+
})
187194
}
188195
189196
$effect(() => {

0 commit comments

Comments
 (0)