Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/little-hotels-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: internally wrap store subscribe in untrack
11 changes: 7 additions & 4 deletions packages/svelte/src/store/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @import { Readable } from './public' */
import { untrack } from '../index-client.js';
import { noop } from '../internal/shared/utils.js';

/**
Expand All @@ -20,10 +21,12 @@ export function subscribe_to_store(store, run, invalidate) {
}

// Svelte store takes a private second argument
const unsub = store.subscribe(
run,
// @ts-expect-error
invalidate
const unsub = untrack(() =>
store.subscribe(
run,
// @ts-expect-error
invalidate
)
);

// Also support RxJS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script>
import { untrack } from "svelte";
import { writable, derived } from "svelte/store";

const obj = writable({ a: 1 });
Expand All @@ -8,9 +7,7 @@

function watch (prop) {
return derived(obj, (o) => {
untrack(() => {
count++;
});
count++;
return o[prop];
});
}
Expand Down