Skip to content

Svelte fails when modifying nested writable stores #4495

@milkbump

Description

@milkbump

Describe the bug
Svelte chokes when altering the content of a nested store using the $ syntax.

(i.e)

<script>
   import { writable } from "svelte/store";
	
   let store = writable({
	inner: writable("string"),
   });
	
  $: ({ inner } = $store);
  $: inner.set("new string");          // this works 
  //$: $inner = "other new string";    // this doesn't
  $: $inner && ($inner = "other other new string"); // this works!?
</script>

<h1>Hello {$inner}!</h1>

Logs
Results in a Cannot read property 'set' of undefined error.

To Reproduce
REPL repro

Expected behavior
I should be able to assign a value to a nested Svelte store using the $ systax.

Severity
Low severity. It's only a convenience, and probably a rarely used pattern to nest stores.

Additional context
I'm not familiar with Svelte internals but I suppose this may be vaguely related to #4079 and #3637 ??

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions