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
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -613,7 +613,7 @@ 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):
616
+
Or using the [new syntax](#svelte:component-is-no-longer-necessary):
617
617
618
618
```svelte
619
619
<script lang="ts">
@@ -635,6 +635,31 @@ The two utility types `ComponentEvents` and `ComponentType` are also deprecated.
635
635
636
636
Because components are no longer classes, using `bind:this` no longer returns a class instance with `$set`, `$on` and `$destroy` methods on it. It only returns the instance exports (`export function/const`) and, if you're using the `accessors` option, a getter/setter-pair for each property.
637
637
638
+
## `<svelte:component>` is no longer necessary
639
+
640
+
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>`.
641
+
642
+
This is no longer true in Svelte 5:
643
+
644
+
```svelte
645
+
<script>
646
+
import A from './A.svelte';
647
+
import B from './B.svelte';
648
+
649
+
let Thing = $state();
650
+
</script>
651
+
652
+
<select bind:value={Thing}>
653
+
<option value={A}>A</option>
654
+
<option value={B}>B</option>
655
+
</select>
656
+
657
+
<!-- these are equivalent -->
658
+
<Thing />
659
+
<svelte:component this={Thing} />
660
+
```
661
+
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.
662
+
638
663
## Whitespace handling changed
639
664
640
665
Previously, Svelte employed a very complicated algorithm to determine if whitespace should be kept or not. Svelte 5 simplifies this which makes it easier to reason about as a developer. The rules are:
@@ -715,31 +740,6 @@ In Svelte 4, doing the following triggered reactivity:
715
740
716
741
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.
717
742
718
-
### `<svelte:component>` is no longer necessary {#svelte-component-no-longer-necessary}
719
-
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>`.
721
-
722
-
This is no longer true in Svelte 5:
723
-
724
-
```svelte
725
-
<script>
726
-
import A from './A.svelte';
727
-
import B from './B.svelte';
728
-
729
-
let Thing = $state();
730
-
</script>
731
-
732
-
<select bind:value={Thing}>
733
-
<option value={A}>A</option>
734
-
<option value={B}>B</option>
735
-
</select>
736
-
737
-
<!-- these are equivalent -->
738
-
<Thing />
739
-
<svelte:component this={Thing} />
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.
742
-
743
743
### Touch and wheel events are passive
744
744
745
745
When using `onwheel`, `onmousewheel`, `ontouchstart` and `ontouchmove` event attributes, the handlers are [passive](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#using_passive_listeners) to align with browser defaults. This greatly improves responsiveness by allowing the browser to scroll the document immediately, rather than waiting to see if the event handler calls `event.preventDefault()`.
0 commit comments