You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/07-misc/07-v5-migration-guide.md
+18-2Lines changed: 18 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -612,6 +612,21 @@ To declare that a component of a certain type is required:
612
612
613
613
<svelte:component this={component} foo="bar" />
614
614
```
615
+
Or using the [new syntax](#svelte-component-no-longer-necessary):
616
+
617
+
```svelte
618
+
<script lang="ts">
619
+
import type { Component } from 'svelte';
620
+
import {
621
+
ComponentA,
622
+
ComponentB
623
+
} from 'component-library';
624
+
let Component: Component<{ foo: string }> = $state(
625
+
Math.random() ? ComponentA : ComponentB
626
+
);
627
+
</script>
628
+
<Component foo="bar" />
629
+
```
615
630
616
631
The two utility types `ComponentEvents` and `ComponentType` are also deprecated. `ComponentEvents` is obsolete because events are defined as callback props now, and `ComponentType` is obsolete because the new `Component` type is the component type already (e.g. `ComponentType<SvelteComponent<{ prop: string }>>` == `Component<{ prop: string }>`).
617
632
@@ -699,9 +714,9 @@ In Svelte 4, doing the following triggered reactivity:
699
714
700
715
This is because the Svelte compiler treated the assignment to `foo.value` as an instruction to update anything that referenced `foo`. In Svelte 5, reactivity is determined at runtime rather than compile time, so you should define `value` as a reactive `$state` field on the `Foo` class. Wrapping `new Foo()` with `$state(...)` will have no effect — only vanilla objects and arrays are made deeply reactive.
701
716
702
-
### `<svelte:component>` is no longer necessary
717
+
### `<svelte:component>` is no longer necessary {#svelte-component-no-longer-necessary}
703
718
704
-
In Svelte 4, components are _static_ — if you render `<Thing>`, and the value of `Thing` changes, [nothing happens](/playground/7f1fa24f0ab44c1089dcbb03568f8dfa?version=4.2.18). To make it dynamic you must use `<svelte:component>`.
719
+
In Svelte 4, components are _static_ — if you render `<Thing>`, and the value of `Thing` changes, [nothing happens](/playground/7f1fa24f0ab44c1089dcbb03568f8dfa?version=4.2.18). To make it dynamic you had to use `<svelte:component>`.
705
720
706
721
This is no longer true in Svelte 5:
707
722
@@ -722,6 +737,7 @@ This is no longer true in Svelte 5:
722
737
<Thing />
723
738
<svelte:component this={Thing} />
724
739
```
740
+
While migrating, keep in mind that your user-defined component's name should be capitalized (`Thing`) to distinguish it from a normal HTML element and avoid incorrect types.
0 commit comments