Skip to content

toStore and reactive variables (legacy) #17419

@aMediocreDad

Description

@aMediocreDad

Describe the bug

Stores created with toStore show inconsistent behaviour when passed as a prop togther with and without the state it was initialized with.

<!-- Parent -->
<!-- If use the input we will observe no reactivity in the child component. -->
<script>
  import { toStore } from "svelte/store"

  import Child from './Component.svelte'
	
  let state = $state({ nested: "Nested Text" })
</script>
<p>Change me: <input bind:value={state.nested} /></p>

<Child store={toStore(() => state)} {state}></Child>

<!-- Child -->
<!-- However if we uncomment the commented out code in the child component we will now
  observe that the {text} variable and the chained reference in the template are reactive
--> 
<svelte:options runes={false} />

<script>
  export let store;
  //export let state;

  $: derived = $store.nested || "nested"
  //$: text = state.nested || "state"
</script>

<p>I am a template chained reference: {$store.nested}</p>
<p>I am a derived variable: {derived}</p>
<!-- <p>I am propped state derived: {text}</p> -->

Expected behaviour is reactivity in both cases where toStore is used. If not possible, consistency is at least expected.

Reproduction

REPL Here: https://svelte.dev/playground/5c4215385e8c49d98e0b45ce2a63f7a8?version=latest

Logs

N/A

System Info

N/A

Severity

blocking all usage of svelte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions