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
@@ -613,6 +613,21 @@ To declare that a component of a certain type is required:
613
613
614
614
<svelte:component this={component} foo="bar" />
615
615
```
616
+
Or using the [new syntax](#svelte-component-no-longer-necessary):
617
+
618
+
```svelte
619
+
<script lang="ts">
620
+
import type { Component } from 'svelte';
621
+
import {
622
+
ComponentA,
623
+
ComponentB
624
+
} from 'component-library';
625
+
let Component: Component<{ foo: string }> = $state(
626
+
Math.random() ? ComponentA : ComponentB
627
+
);
628
+
</script>
629
+
<Component foo="bar" />
630
+
```
616
631
617
632
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 }>`).
618
633
@@ -700,9 +715,9 @@ In Svelte 4, doing the following triggered reactivity:
700
715
701
716
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.
702
717
703
-
### `<svelte:component>` is no longer necessary
718
+
### `<svelte:component>` is no longer necessary {#svelte-component-no-longer-necessary}
704
719
705
-
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>`.
720
+
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>`.
706
721
707
722
This is no longer true in Svelte 5:
708
723
@@ -723,6 +738,7 @@ This is no longer true in Svelte 5:
723
738
<Thing />
724
739
<svelte:component this={Thing} />
725
740
```
741
+
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