Skip to content

Commit d64aee7

Browse files
authored
docs: Add <svelte:component> deprecation section also to preview docs. (#12862)
1 parent cb12431 commit d64aee7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sites/svelte-5-preview/src/routes/docs/content/03-appendix/03-deprecations.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,36 @@ When authoring custom elements, use the new [host rune](/docs/runes#$host) to di
8282
>greet</button>
8383
```
8484

85+
## `<svelte:component>` in runes mode
86+
87+
In previous versions of Svelte, the component constructor was fixed when the component was rendered. In other words, if you wanted `<X>` to re-render when `X` changed, you would either have to use `<svelte:component this={X}>` or put the component inside a `{#key X}...{/key}` block.
88+
89+
In Svelte 5 this is no longer true — if `X` changes, `<X>` re-renders.
90+
91+
In some cases `<object.property>` syntax can be used as a replacement; a lowercased variable with property access is recognized as a component in Svelte 5.
92+
93+
For complex component resolution logic, an intermediary, capitalized variable may be necessary. E.g. in places where `@const` can be used:
94+
95+
```diff
96+
{#each items as item}
97+
- <svelte:component this={item.condition ? Y : Z} />
98+
+ {@const Component = item.condition ? Y : Z}
99+
+ <Component />
100+
{/each}
101+
```
102+
103+
A derived value may be used in other contexts:
104+
105+
```diff
106+
<script>
107+
...
108+
let condition = $state(false);
109+
+ const Component = $derived(condition ? Y : Z);
110+
</script>
111+
- <svelte:component this={condition ? Y : Z} />
112+
+ <Component />
113+
```
114+
85115
Note that using `$props` and `$host` will put you in [runes mode](/docs/runes) — be sure to update your props and state accordingly.
86116

87117
## `immutable`

0 commit comments

Comments
 (0)