Skip to content

Commit 32808ac

Browse files
authored
docs: More guidance on migrating away from <svelte:component>. (#12839)
* More guidance on migrating away from `<svelte:component>`. * Slight adjustments.
1 parent f12a5e4 commit 32808ac

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/svelte/messages/compile-warnings/template.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,31 @@ This code will work when the component is rendered on the client (which is why t
6060
6161
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.
6262

63-
In Svelte 5 this is no longer true — if `X` changes, `<X>` re-renders. For more complex expressions like `condition ? Y : Z` you can use a derived value instead.
63+
In Svelte 5 this is no longer true — if `X` changes, `<X>` re-renders.
64+
65+
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.
66+
67+
For complex component resolution logic, an intermediary, capitalized variable may be necessary. E.g. in places where `@const` can be used:
68+
69+
```diff
70+
{#each items as item}
71+
- <svelte:component this={item.condition ? Y : Z} />
72+
+ {@const Component = item.condition ? Y : Z}
73+
+ <Component />
74+
{/each}
75+
```
76+
77+
A derived value may be used in other contexts:
78+
79+
```diff
80+
<script>
81+
...
82+
let condition = $state(false);
83+
+ const Component = $derived(condition ? Y : Z);
84+
</script>
85+
- <svelte:component this={condition ? Y : Z} />
86+
+ <Component />
87+
```
6488

6589
## svelte_element_invalid_this
6690

0 commit comments

Comments
 (0)