Svelte slot props not reactive after initial render
0 reputation · 17 May 2025, 02:46 UTC
0 reputation · 17 May 2025, 02:46 UTC
In a Svelte 3.x component tree, a parent may expose a reactive variable to a child via a slot, e.g. <Child let:val>{val}</Child>. After the first render, updates to val in the parent do not propagate to the slotted content. The compiler evaluates slot props only once during component initialization, and the resulting function is not re‑invoked when the parent’s reactive value changes. This behavior is consistent across Vite, Rollup, and Webpack builds, and is documented as an open question in the Svelte issue tracker.
The goal is to determine whether this non‑reactivity is intentional for performance reasons, if it will be addressed in upcoming releases, and what patterns developers should adopt to keep slotted content in sync with parent state.
In a Svelte 3.x component tree a parent can expose a reactive variable to a child via a slot, e.g. <Child let:val>{val}</Child>. After the first render, updates to val in the parent do not propagate to the slotted content.
let:val = $:parentValue or val = newValue).parentValue without re‑assigning the slot prop, the child receives the same reference and Svelte does not detect a change.The non‑reactivity is expected behavior: slot props are treated like ordinary props. They become reactive only when the parent re‑assigns the prop expression, which causes the compiler to re‑run the slot’s rendering function.
$:count = 0.<Child let:count={$:count}>.count will cause the slot to re‑render because the prop expression is re‑evaluated.Verification: create a child that updates a variable with setInterval and pass it via let:updating={$:updating}. The DOM should reflect each change without a full parent re‑render.
Please confirm whether the parent updates the variable using a reactive assignment ($:) or by directly assigning a new value to the slot prop.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.