Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind:this fails with store #3591

Closed
davidaq opened this issue Sep 19, 2019 · 1 comment · Fixed by #3743
Closed

bind:this fails with store #3591

davidaq opened this issue Sep 19, 2019 · 1 comment · Fixed by #3743
Labels

Comments

@davidaq
Copy link
Contributor

davidaq commented Sep 19, 2019

Describe the bug
Using bind:this and a writable store together doesn't provide expected behavior.

Logs
No error log.

To Reproduce
Can be reproduced in REPL:

<script>
import { writable } from 'svelte/store'
let ref = writable(null)
</script>

<h1 bind:this={$ref}>HELLO</h1>
<i>{$ref ? $ref.innerHTML : ''}</i>

Expected behavior
Expect to see two lines of "HELLO". The second "HELLO" inside <i> didn't show up as expected.

Severity
Can be worked around.

Work around

<script>
import { writable } from 'svelte/store'
let ref = writable({})
</script>

<h1 bind:this={$ref.el}>HELLO</h1>
<i>{$ref.el ? $ref.el.innerHTML : ''}</i>
@Conduitry Conduitry added the bug label Sep 21, 2019
@Conduitry
Copy link
Member

This looks to be fixed by

diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts
index ee24fc70..042a755f 100644
--- a/src/compiler/compile/Component.ts
+++ b/src/compiler/compile/Component.ts
@@ -777,7 +777,7 @@ export default class Component {
 		}
 
 		if (name[0] === '$' && name[1] !== '$') {
-			return x`${name.slice(1)}.set(${name})`;
+			return x`${name.slice(1)}.set(${value || name})`;
 		}
 
 		if (

but I'm now wondering what else with stores might be fixed by this, as this change isn't specific to bind:this at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants