Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42f5d10
Store deriveds old value before updating them for consistency with di…
raythurnvoid Jun 29, 2025
1fc9f08
Add tests for derived old values in teardown functions
raythurnvoid Jun 29, 2025
9d9b64b
Add tests for props old values in onDestroy hooks to prevent regressions
raythurnvoid Jun 29, 2025
5ed74b2
Add changeset
raythurnvoid Jun 29, 2025
b213de2
Update comment
raythurnvoid Jun 29, 2025
562c9e3
remove extraneous tests - these pass with or without the src change
Rich-Harris Jun 30, 2025
85268bc
revert
Rich-Harris Jun 30, 2025
0ad9588
WIP
Rich-Harris Jul 1, 2025
8a6d5ed
simplify props
Rich-Harris Jul 1, 2025
e0ebcc8
simplify
Rich-Harris Jul 1, 2025
9506889
tweak
Rich-Harris Jul 1, 2025
2a16f17
reorder a bit
Rich-Harris Jul 1, 2025
b141f60
simplify
Rich-Harris Jul 1, 2025
ab1ea27
unused
Rich-Harris Jul 1, 2025
bdd5897
more
Rich-Harris Jul 1, 2025
1253886
more
Rich-Harris Jul 1, 2025
c9cf7e3
tweak
Rich-Harris Jul 1, 2025
73d66a8
also appears to be unnecessary
Rich-Harris Jul 1, 2025
dfbce4d
changeset
Rich-Harris Jul 1, 2025
29cfec1
Merge branch 'simpler-props' into gh-16263
Rich-Harris Jul 1, 2025
884d431
fix
Rich-Harris Jul 1, 2025
5083231
merge main
Rich-Harris Jul 1, 2025
809693c
Update .changeset/light-rivers-jump.md
Rich-Harris Jul 1, 2025
f32818c
easier debugging
Rich-Harris Jul 1, 2025
4a89898
fix
Rich-Harris Jul 1, 2025
79e7203
Merge branch 'gh-16263' of github.com:sveltejs/svelte into gh-16263
Rich-Harris Jul 1, 2025
05636d3
WIP
Rich-Harris Jul 2, 2025
c8ab9e6
fix
Rich-Harris Jul 2, 2025
99f0464
merge
Rich-Harris Jul 2, 2025
cff7ed6
merge main
Rich-Harris Jul 2, 2025
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/light-rivers-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

Store deriveds old value before updating them for consistency with directly assigned sources when reading in teardown functions
1 change: 0 additions & 1 deletion packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ export function prop(props, key, flags, fallback) {
return value;
}

// TODO is this still necessary post-#16263?
if (has_destroyed_component_ctx(d)) {
return d.v;
}
Expand Down
19 changes: 15 additions & 4 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from './constants.js';
import { flush_tasks } from './dom/task.js';
import { internal_set, old_values } from './reactivity/sources.js';
import { destroy_derived_effects, update_derived } from './reactivity/deriveds.js';
import { destroy_derived_effects, execute_derived, update_derived } from './reactivity/deriveds.js';
import * as e from './errors.js';

import { tracing_mode_flag } from '../flags/index.js';
Expand Down Expand Up @@ -769,7 +769,7 @@ export function get(signal) {
}
}

if (is_derived) {
if (is_derived && !is_destroying_effect) {
derived = /** @type {Derived} */ (signal);

if (check_dirtiness(derived)) {
Expand Down Expand Up @@ -810,8 +810,19 @@ export function get(signal) {
}
}

if (is_destroying_effect && old_values.has(signal)) {
return old_values.get(signal);
if (is_destroying_effect) {
if (old_values.has(signal)) {
return old_values.get(signal);
}

if (is_derived) {
derived = /** @type {Derived} */ (signal);

var value = (derived.f & CLEAN) !== 0 ? execute_derived(derived) : derived.v;
old_values.set(derived, value);

return value;
}
}

return signal.v;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
async test({ assert, logs, target }) {
const [increment] = target.querySelectorAll('button');

flushSync(() => increment.click());
flushSync(() => increment.click());
flushSync(() => increment.click());

assert.deepEqual(logs, [
'count: 1',
'squared: 1',
'count: 2',
'squared: 4',
'count: 3',
'squared: 9',
'count: 4'
]);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script>
let count = $state(1);
let squared = $derived(count * count);

$effect(() => {
console.log(`count: ${count}`);

return () => {
console.log(`squared: ${squared}`);
};
});
</script>

<button onclick={() => count++}>increment</button>

<p>count: {count}</p>

{#if count % 2 === 0}
<p id="squared">squared: {squared}</p>
{/if}