-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the problem
Re-submission of kit#13123 to here.
I want to run some code in a component in children, even if the snippet is conditionally rendered. The use case I have in mind is debugging and meta-programming related.
Describe the proposed solution
Set using <svelte:options>, a component's <script> always runs when the component is used in the markup and not in a comment, even if the component is otherwise not rendered.
Alternatives considered
Also set using <svelte:options>, a component that is unaffected by {#if}, {:else}, {:else if} and possibly {:then} of the await-then block. In other words, they are always mounted/called. Leaning towards the proposed solution, because this alternative affects rendering of children components and elements, while the proposed solution is more modular.
Another alternative is a different block, {#run} or {#always}, that implements either the proposed or the alternative solution, but instead of changing component options, a new template block is introduced.
Additional Information
For example when there is {#if a()} ... {#if b()} ... {/if}{/if} then the solution should allow such component <script> in the inner {#if b()} to run even if the branch is not rendered.
Importance
would make my life easier