Skip to content

Passing a Writable as prop to a component doesn't allow "$" access #11742

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

Closed
i-m-luke opened this issue May 23, 2024 · 2 comments · Fixed by #11768
Closed

Passing a Writable as prop to a component doesn't allow "$" access #11742

i-m-luke opened this issue May 23, 2024 · 2 comments · Fixed by #11768
Labels
Milestone

Comments

@i-m-luke
Copy link

Describe the bug

When a Writable is passed to a component as prop and then the prop is accessed by "$" sign then this error occurs: "Can only bind to state or props". It works with non-rune props declaration.

Reproduction

REPL: https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACj2OwWrDMBBEf2VYAm3B4LtiG_oVPUQ92NamXqpIQlrHCcb_HpxAjjPMPN5KZ_FcyJxWCv2FydB3SlSR3tMeypW9MlVU4pzHvWnKmCVpZwMA1DX4lmJWeFYU7ZUNfrJoP3huimYJf90ROknBEvN_seF9XEQn6MQYo2MM7H1cIAoXuYQPfe5f4529vujY0OKQckzl8-toQ1O_fWxoJKRZsbu3lpRvagmDBGeuvZ-5XQ9Pxoa6o4ou0clZ2JHRPPP2uz0AAC8RWA0BAAA=

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz
    Memory: 2.01 GB / 15.91 GB
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 124.0.6367.210
    Edge: Chromium (124.0.2478.105)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    svelte: ^5.0.0-next.136 => 5.0.0-next.136

Severity

annoyance

@brunnerh
Copy link
Member

brunnerh commented May 23, 2024

$state is a rune, you cannot have a store with the same name and expect that to work in runes mode.
Apparently that should be possible, the following would be a workaround:
Rename it to anything that does not conflict.

<script>
    let { state: store } = $props();
</script>
<input type="text" bind:value={$store} />

@Conduitry
Copy link
Member

I think there is a slight bug here. Having a state variable in the component's scope is supposed to disable the $state rune (in that it becomes an autosubscription to the state store) - and the same thing with the other runes - but apparently that's not happening for component scope that's coming from props.

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.

4 participants