Skip to content

Commit c6e2332

Browse files
committed
feat: make transitions local by default
To make them global, add the |global modifier This is a breaking change closes #6686
1 parent a40af4d commit c6e2332

File tree

18 files changed

+59
-38
lines changed

18 files changed

+59
-38
lines changed

site/content/docs/03-template-syntax.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,12 @@ transition:fn
994994
transition:fn={params}
995995
```
996996
```sv
997+
transition:fn|global
998+
```
999+
```sv
1000+
transition:fn|global={params}
1001+
```
1002+
```sv
9971003
transition:fn|local
9981004
```
9991005
```sv
@@ -1027,7 +1033,28 @@ The `transition:` directive indicates a *bidirectional* transition, which means
10271033
{/if}
10281034
```
10291035

1030-
> By default intro transitions will not play on first render. You can modify this behaviour by setting `intro: true` when you [create a component](/docs#run-time-client-side-component-api).
1036+
---
1037+
1038+
Transitions are local by default (in Svelte 3, they were global by default). Local transitions only play when the block they belong to is created or destroyed, *not* when parent blocks are created or destroyed.
1039+
1040+
```sv
1041+
{#if x}
1042+
{#if y}
1043+
<!-- Svelte 3: <p transition:fade|local> -->
1044+
<p transition:fade>
1045+
fades in and out only when y changes
1046+
</p>
1047+
1048+
<!-- Svelte 3: <p transition:fade> -->
1049+
<p transition:fade|global>
1050+
fades in and out when x or y change
1051+
</p>
1052+
1053+
{/if}
1054+
{/if}
1055+
```
1056+
1057+
> By default intro transitions will not play on first render. You can modify this behaviour by setting `intro: true` when you [create a component](/docs#run-time-client-side-component-api) and marking the transition as `global`.
10311058
10321059
##### Transition parameters
10331060

@@ -1153,24 +1180,6 @@ An element with transitions will dispatch the following events in addition to an
11531180
{/if}
11541181
```
11551182

1156-
---
1157-
1158-
Local transitions only play when the block they belong to is created or destroyed, *not* when parent blocks are created or destroyed.
1159-
1160-
```sv
1161-
{#if x}
1162-
{#if y}
1163-
<p transition:fade>
1164-
fades in and out when x or y change
1165-
</p>
1166-
1167-
<p transition:fade|local>
1168-
fades in and out only when y changes
1169-
</p>
1170-
{/if}
1171-
{/if}
1172-
```
1173-
11741183

11751184
#### in:*fn*/out:*fn*
11761185

@@ -1181,6 +1190,12 @@ in:fn
11811190
in:fn={params}
11821191
```
11831192
```sv
1193+
in:fn|global
1194+
```
1195+
```sv
1196+
in:fn|global={params}
1197+
```
1198+
```sv
11841199
in:fn|local
11851200
```
11861201
```sv
@@ -1194,6 +1209,12 @@ out:fn
11941209
out:fn={params}
11951210
```
11961211
```sv
1212+
out:fn|global
1213+
```
1214+
```sv
1215+
out:fn|global={params}
1216+
```
1217+
```sv
11971218
out:fn|local
11981219
```
11991220
```sv

src/compiler/compile/nodes/Transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Transition extends Node {
2828
this.name = info.name;
2929
component.add_reference(/** @type {any} */ (this), info.name.split('.')[0]);
3030
this.directive = info.intro && info.outro ? 'transition' : info.intro ? 'in' : 'out';
31-
this.is_local = info.modifiers.includes('local');
31+
this.is_local = !info.modifiers.includes('global');
3232
if ((info.intro && parent.intro) || (info.outro && parent.outro)) {
3333
const parent_transition = parent.intro || parent.outro;
3434
component.error(

src/compiler/compile/render_dom/wrappers/Element/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ export default class ElementWrapper extends Wrapper {
422422
`);
423423
}
424424
if (this.child_dynamic_element_block.has_intros) {
425-
block.chunks.intro.push(b`@transition_in(${this.var});`);
425+
block.chunks.intro.push(b`@transition_in(${this.var}, #local);`);
426426
}
427427
if (this.child_dynamic_element_block.has_outros) {
428-
block.chunks.outro.push(b`@transition_out(${this.var});`);
428+
block.chunks.outro.push(b`@transition_out(${this.var}, #local);`);
429429
}
430430
block.chunks.destroy.push(b`if (${this.var}) ${this.var}.d(detaching)`);
431431
if (this.node.animation) {

test/js/samples/transition-local/input.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
{#if x}
99
{#if y}
10-
<div in:foo|local>...</div>
10+
<div in:foo>...</div>
1111
{/if}
1212
{/if}

test/runtime/samples/dynamic-element-transition/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
</script>
1414

1515
{#if visible}
16-
<svelte:element this={tag} transition:foo></svelte:element>
16+
<svelte:element this={tag} transition:foo|global></svelte:element>
1717
{/if}

test/runtime/samples/transition-js-await-block-outros/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</script>
1313

1414
{#await promise}
15-
<p class='pending' transition:foo>loading...</p>
15+
<p class='pending' transition:foo|global>loading...</p>
1616
{:then value}
1717
<p class='then' transition:foo>{value}</p>
1818
{:catch error}

test/runtime/samples/transition-js-await-block/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</script>
1313

1414
{#await promise}
15-
<p class='pending' transition:foo>loading...</p>
15+
<p class='pending' transition:foo|global>loading...</p>
1616
{:then value}
1717
<p class='then' transition:foo>{value}</p>
1818
{:catch error}

test/runtime/samples/transition-js-each-block-intro/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
</script>
1313

1414
{#each things as thing}
15-
<div in:foo>{thing}</div>
15+
<div in:foo|global>{thing}</div>
1616
{/each}

test/runtime/samples/transition-js-each-block-keyed-intro-outro/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
</script>
1313

1414
{#each things as thing (thing.name)}
15-
<div transition:foo>{thing.name}</div>
15+
<div transition:foo|global>{thing.name}</div>
1616
{/each}

test/runtime/samples/transition-js-each-block-keyed-intro/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
</script>
1313

1414
{#each things as thing (thing.name)}
15-
<div in:foo>{thing.name}</div>
15+
<div in:foo|global>{thing.name}</div>
1616
{/each}

test/runtime/samples/transition-js-if-block-in-each-block-bidi/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
{#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number}
1515
{#if threshold >= number}
16-
<div transition:foo>{number}</div>
16+
<div transition:foo|global>{number}</div>
1717
{/if}
1818
{/each}

test/runtime/samples/transition-js-intro-enabled-by-option/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
}
1010
</script>
1111

12-
<div transition:foo></div>
12+
<div transition:foo|global></div>

test/runtime/samples/transition-js-local-and-global/main.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
{#if x}
1616
{#if y}
17-
<div transition:foo|local>snaps if x changes</div>
18-
<div transition:foo>transitions if x changes</div>
17+
<div transition:foo>snaps if x changes</div>
18+
<div transition:foo|global>transitions if x changes</div>
1919
{/if}
2020
{/if}

test/runtime/samples/transition-js-local/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
{#if x}
1616
{#if y}
17-
<div transition:foo|local></div>
17+
<div transition:foo></div>
1818
{/if}
1919
{/if}

test/runtime/samples/transition-js-nested-await/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
{#if x}
1616
{#await promise then value}
17-
<div transition:foo></div>
17+
<div transition:foo|global></div>
1818
{/await}
1919
{/if}

test/runtime/samples/transition-js-nested-each-keyed/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
{#if x}
1616
{#each things as thing (thing)}
17-
<div transition:foo></div>
17+
<div transition:foo|global></div>
1818
{/each}
1919
{/if}

test/runtime/samples/transition-js-nested-each/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
{#if x}
1616
{#each things as thing}
17-
<div transition:foo></div>
17+
<div transition:foo|global></div>
1818
{/each}
1919
{/if}

test/runtime/samples/transition-js-nested-if/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
{#if x}
1616
{#if y}
17-
<div transition:foo></div>
17+
<div transition:foo|global></div>
1818
{/if}
1919
{/if}

0 commit comments

Comments
 (0)