Skip to content

Svelte 5: $effect somewhat broken between v247 and v248 #13296

Closed
@brunnerh

Description

@brunnerh

Describe the bug

A dependency seems to not be tracked correctly in certain scenarios.
The example uses a $derived.by to destructure props from a stateful object updated via $effect.

Reproduction

<script>
	import { useData } from './data.svelte.js';

	const { data, next } = $derived.by(useData);
</script>

<button onclick={() => next()}>
	Next
</button>
 
<pre>{JSON.stringify(data, null, 2)}</pre>
// data.svelte.js
export function useData() {
  let data = $state(null);
  let i = $state(1);

  $effect(() => {
    fetchData(i);

    async function fetchData(index) {
      const res = await fetch(`https://dummyjson.com/posts/${index}`);
      const json = await res.json();

      data = json;
    }
  });

  return {
    get data() {
      return data;
    },
    next() { i++; },
  }
}

REPL

The data updates initially, but changing the index does not re-trigger past v247.

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions