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

$foo = $foo gets completely compiled away #2681

Closed
Conduitry opened this issue May 5, 2019 · 3 comments · Fixed by #2683
Closed

$foo = $foo gets completely compiled away #2681

Conduitry opened this issue May 5, 2019 · 3 comments · Fixed by #2683
Assignees
Labels

Comments

@Conduitry
Copy link
Member

If you've mutated and autosubscription value without an assignment being involved, it will now be out of date with the actual store. Presumably, this is how we want this to behave, and something like $foo.push(whatever); shouldn't get instrumented.

Also presumably, the way to deal with this is to then do $foo = $foo; which will compile to foo.set($foo);, but currently that is getting compiled away into nothing.

@Conduitry Conduitry added the bug label May 5, 2019
@Conduitry Conduitry changed the title $foo = $foo gets cvompletely compiled away $foo = $foo gets completely compiled away May 5, 2019
@Conduitry Conduitry self-assigned this May 5, 2019
@Conduitry
Copy link
Member Author

I believe this is just a matter of:

diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts
index ce2f3a00..0a0743b2 100644
--- a/src/compile/render-dom/index.ts
+++ b/src/compile/render-dom/index.ts
@@ -182,7 +182,7 @@ export default function dom(
 
 					if (node.operator === '=' && nodes_match(node.left, node.right)) {
 						const dirty = names.filter(name => {
-							return scope.find_owner(name) === component.instance_scope;
+							return name[0] === '$' || scope.find_owner(name) === component.instance_scope;
 						});
 
 						if (dirty.length) component.has_reactive_assignments = true;

Anything that begins with a $ should also be considered dirty, because even if it's an auto-subscription to some unknown global, we can still make it reactive.

@beenotung
Copy link

variable name starting with $ mush be a store, is that your case?

@Conduitry
Copy link
Member Author

Conduitry commented May 5, 2019

Variable names that begin with a $ are reserved in Svelte to always be auto-subscriptions to a store. You can't use variables beginning with a $ for anything else.

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