Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-rocks-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: `@attach` opt's you into runes mode
3 changes: 3 additions & 0 deletions documentation/docs/03-template-syntax/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Attachments are functions that run when an element is mounted to the DOM. Option
> [!NOTE]
> Attachments are available in Svelte 5.29 and newer.

> [!NOTE]
> Attachments also opt you in for runes mode so if you use them in a legacy component you would have to also migrate that component.

```svelte
<!--- file: App.svelte --->
<script>
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/99-legacy/00-legacy-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ The following pages document these features for
- people still using Svelte 3/4
- people using Svelte 5, but with components that haven't yet been migrated

Since Svelte 3/4 syntax still works in Svelte 5, we will distinguish between _legacy mode_ and _runes mode_. Once a component is in runes mode (which you can opt into by using runes, or by explicitly setting the `runes: true` compiler option), legacy mode features are no longer available.
Since Svelte 3/4 syntax still works in Svelte 5, we will distinguish between _legacy mode_ and _runes mode_. Once a component is in runes mode (which you can opt into by using runes or attachments, or by explicitly setting the `runes: true` compiler option), legacy mode features are no longer available.

If you're exclusively interested in the Svelte 3/4 syntax, you can browse its documentation at [v4.svelte.dev](https://v4.svelte.dev).
18 changes: 17 additions & 1 deletion packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,23 @@ export function analyze_component(root, source, options) {

const component_name = get_component_name(options.filename);

const runes = options.runes ?? Array.from(module.scope.references.keys()).some(is_rune);
let runes = options.runes ?? Array.from(module.scope.references.keys()).some(is_rune);

// if we are not in runes mode by the bindings we need to check if there's any attachment
if (!runes) {
// we need to do it beforehand otherwise we would not be in runes mode until we hit an attachment
walk(
/** @type {AST.SvelteNode} */ (template.ast),
{},
{
AttachTag(_, context) {
runes = true;
// once we found one we can stop the traversal
context.stop();
}
}
);
}

if (!runes) {
for (let check of synthetic_stores_legacy_check) {
Expand Down