Repository: sveltejs/svelte (JavaScript)
Date: 2021-07-11 13:28:01+00:00
Task type: Bug Fix

Issue:
Dynamic properties in transition "in" directive not working
### Describe the bug

When the params passed to "in" transition is changed dynamically, the value is not reflected.
The values passed to "out" work fine.

### Reproduction

https://svelte.dev/repl/ca9e1328264c4f3395d72d786c9aa113?version=3.38.3

### Logs

_No response_

### System Info

```shell
REPL
```


### Severity

annoyance


https://user-images.githubusercontent.com/10703445/124812334-16ba1080-df81-11eb-814f-b766bf21d036.mov




Issue discussion:

Solution patch:
diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts
--- a/src/compiler/compile/render_dom/wrappers/Element/index.ts
+++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts
@@ -754,7 +754,7 @@ export default class ElementWrapper extends Wrapper {
 					intro_block = b`
 						@add_render_callback(() => {
 							if (${outro_name}) ${outro_name}.end(1);
-							if (!${intro_name}) ${intro_name} = @create_in_transition(${this.var}, ${fn}, ${snippet});
+							${intro_name} = @create_in_transition(${this.var}, ${fn}, ${snippet});
 							${intro_name}.start();
 						});
 					`;


Test patch:
diff --git a/test/runtime/samples/transition-css-in-out-in-with-param/_config.js b/test/runtime/samples/transition-css-in-out-in-with-param/_config.js
new file mode 100644
--- /dev/null
+++ b/test/runtime/samples/transition-css-in-out-in-with-param/_config.js
@@ -0,0 +1,21 @@
+export default {
+	test({ assert, component, target, window, raf }) {
+		component.visible = true;
+		const div = target.querySelector('div');
+
+		// animation duration of `in` should be 10ms.
+		assert.equal(div.style.animation, '__svelte_1670736059_0 10ms linear 0ms 1 both');
+
+		// animation duration of `out` should be 5ms.
+		component.visible = false;
+		assert.equal(div.style.animation, '__svelte_1670736059_0 10ms linear 0ms 1 both, __svelte_1998461463_0 5ms linear 0ms 1 both');
+
+		// change param
+		raf.tick(1);
+		component.param = true;
+		component.visible = true;
+
+		// animation duration of `in` should be 20ms.
+		assert.equal(div.style.animation, '__svelte_722598827_0 20ms linear 0ms 1 both');
+	}
+};
diff --git a/test/runtime/samples/transition-css-in-out-in-with-param/main.svelte b/test/runtime/samples/transition-css-in-out-in-with-param/main.svelte
new file mode 100644
--- /dev/null
+++ b/test/runtime/samples/transition-css-in-out-in-with-param/main.svelte
@@ -0,0 +1,26 @@
+<script>
+	export let visible = false;
+	export let param = false;
+
+	function getInParam() {
+		return { 
+			duration: param ? 20 : 10,
+			css: t => {
+				return `opacity: ${t}`;
+			}
+		};
+	}
+
+	function getOutParam() {
+		return { 
+			duration: param ? 15 : 5,
+			css: t => {
+				return `opacity: ${t}`;
+			}
+		};
+	}
+</script>
+
+{#if visible}
+	<div in:getInParam out:getOutParam></div>
+{/if}
\ No newline at end of file
diff --git a/test/runtime/samples/transition-css-in-out-in/_config.js b/test/runtime/samples/transition-css-in-out-in/_config.js
--- a/test/runtime/samples/transition-css-in-out-in/_config.js
+++ b/test/runtime/samples/transition-css-in-out-in/_config.js
@@ -15,6 +15,6 @@ export default {
 		component.visible = true;
 
 		// reset original styles
-		assert.equal(div.style.animation, '__svelte_3809512021_1 100ms linear 0ms 1 both');
+		assert.equal(div.style.animation, '__svelte_3809512021_0 100ms linear 0ms 1 both');
 	}
 };