Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/calm-dates-track.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: track SvelteDate snapshots in reactions
2 changes: 2 additions & 0 deletions packages/svelte/src/internal/shared/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ function clone(value, cloned, path, paths, original = null, no_tojson = false) {
}

if (value instanceof Date) {
// Ensure SvelteDate snapshots are tracked
value.getTime();
return /** @type {Snapshot<T>} */ (structuredClone(value));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test } from '../../test';
import { tick } from 'svelte';

export default test({
async test({ assert, target }) {
assert.htmlEqual(target.innerHTML, '<button>update</button><p>1970-01-01T00:00:00.000Z</p>');

target.querySelector('button')?.click();
await tick();

assert.htmlEqual(target.innerHTML, '<button>update</button><p>1970-01-02T00:00:00.000Z</p>');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import { SvelteDate } from 'svelte/reactivity';

const date = new SvelteDate(0);
const snapshot = $derived($state.snapshot(date));
</script>

<button onclick={() => date.setTime(86400000)}>update</button>
<p>{snapshot.toISOString()}</p>