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

Proxy Store does not work in components with Auto-Subscription but works in components without Auto-Subscription #5019

Closed
firewave-remo opened this issue Jun 15, 2020 · 4 comments
Labels

Comments

@firewave-remo
Copy link

firewave-remo commented Jun 15, 2020

Describe the bug
I have implemented my own store with a proxy implementation, so that i don't have to call store.set(...) or store.update(...).

This works perfectly fine if the store is used in a component without Auto-Subscription of the store. But as soon as the store is used in a component which Auto-Subscribes the store, the app crashes and doesn't even show the page. Just a console error Cannot read property 'foo' of undefined. Even though the implementation is exactly the same.

To Reproduce
Repl:
https://svelte.dev/repl/c1b53139e2bb45be8eec3f23d5530770?version=3.23.2

First click on the button Change Foo in Test.svelte. Everything works as expected. Then try to uncomment // proxyStore.foo = "Bar"; in App.svelte and you will see the error Cannot read property 'foo' of undefined

Expected behavior
No errors are shown and changing the property of the store should work also in the component that uses Auto-Subscription

Information about your Svelte project:

  • Chrome

  • Linux Mint

  • Svelte version 3.23.2

  • Rollup

Severity
Very annoying bug. Unexpected behavior

@Conduitry
Copy link
Member

This appears to be unrelated to it being a proxy. The core of the issue is:

<script>
	import store from './somewhere.js';
	store.foo = 42;
</script>

{$store}

The presence of the store.foo = 42 for some reason prevents the compiler from emitting the required component_subscribe($$self, store, $$value => $$invalidate(0, $store = $$value));, which means that the autosubscribed $store variable remains undefined. This only appears to happen if the store itself is imported, and not if it's declared and defined in this component.

@skippednote
Copy link
Contributor

@Conduitry I guess we can close this now.

@firewave-remo
Copy link
Author

When will the next release happen? I am really looking forward to this!

@Conduitry
Copy link
Member

This should be fixed in 3.24.0.

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

No branches or pull requests

3 participants