Skip to content

Commit f5954fa

Browse files
committed
docs: move <svelte:component> section out of Breaking Changes, since it is not breaking. Change links.
1 parent 213d70b commit f5954fa

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

documentation/docs/07-misc/07-v5-migration-guide.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ To declare that a component of a certain type is required:
613613
614614
<svelte:component this={component} foo="bar" />
615615
```
616-
Or using the [new syntax](#svelte-component-no-longer-necessary):
616+
Or using the [new syntax](#svelte:component-is-no-longer-necessary):
617617

618618
```svelte
619619
<script lang="ts">
@@ -635,6 +635,31 @@ The two utility types `ComponentEvents` and `ComponentType` are also deprecated.
635635

636636
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.
637637

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+
638663
## Whitespace handling changed
639664

640665
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:
715740

716741
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.
717742

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-
743743
### Touch and wheel events are passive
744744

745745
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

Comments
 (0)