Skip to content

Commit b386784

Browse files
committed
Merge branch 'main' into aa
2 parents a4eb7f7 + c75f1f5 commit b386784

File tree

10 files changed

+79
-21
lines changed

10 files changed

+79
-21
lines changed

.changeset/cuddly-walls-pretend.md

-5
This file was deleted.

.changeset/cyan-games-cheat.md

-5
This file was deleted.

packages/svelte/CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# svelte
22

3+
## 5.19.1
4+
5+
### Patch Changes
6+
7+
- fix: omit unnecessary nullish coallescing in template expressions ([#15056](https://github.com/sveltejs/svelte/pull/15056))
8+
9+
- fix: more efficient template effect grouping ([#15050](https://github.com/sveltejs/svelte/pull/15050))
10+
11+
- fix: ensure untrack correctly retains the active reaction ([#15065](https://github.com/sveltejs/svelte/pull/15065))
12+
13+
- fix: initialize `files` bind on hydration ([#15059](https://github.com/sveltejs/svelte/pull/15059))
14+
315
## 5.19.0
416

517
### Minor Changes

packages/svelte/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.19.0",
5+
"version": "5.19.1",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/internal/client/dom/elements/bindings/input.js

+9
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ export function bind_files(input, get, set = get) {
259259
set(input.files);
260260
});
261261

262+
if (
263+
// If we are hydrating and the value has since changed,
264+
// then use the updated value from the input instead.
265+
hydrating &&
266+
input.files
267+
) {
268+
set(input.files);
269+
}
270+
262271
render_effect(() => {
263272
input.files = get();
264273
});

packages/svelte/src/internal/client/reactivity/effects.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
set_is_flushing_effect,
1717
set_signal_status,
1818
untrack,
19-
skip_reaction
19+
skip_reaction,
20+
untracking
2021
} from '../runtime.js';
2122
import {
2223
DIRTY,
@@ -43,8 +44,7 @@ import * as e from '../errors.js';
4344
import { DEV } from 'esm-env';
4445
import { define_property } from '../../shared/utils.js';
4546
import { get_next_sibling } from '../dom/operations.js';
46-
import { derived, derived_safe_equal, destroy_derived } from './deriveds.js';
47-
import { legacy_mode_flag } from '../../flags/index.js';
47+
import { derived, destroy_derived } from './deriveds.js';
4848

4949
/**
5050
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
@@ -166,7 +166,7 @@ function create_effect(type, fn, sync, push = true) {
166166
* @returns {boolean}
167167
*/
168168
export function effect_tracking() {
169-
if (active_reaction === null) {
169+
if (active_reaction === null || untracking) {
170170
return false;
171171
}
172172

packages/svelte/src/internal/client/reactivity/sources.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
set_derived_sources,
1818
check_dirtiness,
1919
set_is_flushing_effect,
20-
is_flushing_effect
20+
is_flushing_effect,
21+
untracking
2122
} from '../runtime.js';
2223
import { equals, safe_equals } from './equality.js';
2324
import {
@@ -148,6 +149,7 @@ export function mutate(source, value) {
148149
export function set(source, value) {
149150
if (
150151
active_reaction !== null &&
152+
!untracking &&
151153
is_runes() &&
152154
(active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 &&
153155
// If the source was created locally within the current derived, then

packages/svelte/src/internal/client/runtime.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ let dev_effect_stack = [];
8383
/** @type {null | Reaction} */
8484
export let active_reaction = null;
8585

86+
export let untracking = false;
87+
8688
/** @param {null | Reaction} reaction */
8789
export function set_active_reaction(reaction) {
8890
active_reaction = reaction;
@@ -428,6 +430,7 @@ export function update_reaction(reaction) {
428430
var previous_skip_reaction = skip_reaction;
429431
var prev_derived_sources = derived_sources;
430432
var previous_component_context = component_context;
433+
var previous_untracking = untracking;
431434
var flags = reaction.f;
432435

433436
new_deps = /** @type {null | Value[]} */ (null);
@@ -437,6 +440,7 @@ export function update_reaction(reaction) {
437440
skip_reaction = !is_flushing_effect && (flags & UNOWNED) !== 0;
438441
derived_sources = null;
439442
component_context = reaction.ctx;
443+
untracking = false;
440444
read_version++;
441445

442446
try {
@@ -502,6 +506,7 @@ export function update_reaction(reaction) {
502506
skip_reaction = previous_skip_reaction;
503507
derived_sources = prev_derived_sources;
504508
component_context = previous_component_context;
509+
untracking = previous_untracking;
505510
}
506511
}
507512

@@ -944,7 +949,7 @@ export function get(signal) {
944949
}
945950

946951
// Register the dependency on the current reaction signal.
947-
if (active_reaction !== null) {
952+
if (active_reaction !== null && !untracking) {
948953
if (derived_sources !== null && derived_sources.includes(signal)) {
949954
e.state_unsafe_local_read();
950955
}
@@ -1117,12 +1122,12 @@ export function invalidate_inner_signals(fn) {
11171122
* @returns {T}
11181123
*/
11191124
export function untrack(fn) {
1120-
const previous_reaction = active_reaction;
1125+
var previous_untracking = untracking;
11211126
try {
1122-
active_reaction = null;
1127+
untracking = true;
11231128
return fn();
11241129
} finally {
1125-
active_reaction = previous_reaction;
1130+
untracking = previous_untracking;
11261131
}
11271132
}
11281133

packages/svelte/src/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* The current version, as set in package.json.
55
* @type {string}
66
*/
7-
export const VERSION = '5.19.0';
7+
export const VERSION = '5.19.1';
88
export const PUBLIC_VERSION = '5';

packages/svelte/tests/signals/test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,46 @@ describe('signals', () => {
803803
};
804804
});
805805

806+
test('deriveds containing effects work correctly when used with untrack', () => {
807+
return () => {
808+
let a = render_effect(() => {});
809+
let b = state(0);
810+
let c;
811+
let effects = [];
812+
813+
const destroy = effect_root(() => {
814+
a = render_effect(() => {
815+
c = derived(() => {
816+
$.untrack(() => {
817+
effects.push(
818+
effect(() => {
819+
$.get(b);
820+
})
821+
);
822+
});
823+
$.get(b);
824+
});
825+
$.get(c);
826+
});
827+
});
828+
829+
assert.deepEqual(c!.children?.length, 1);
830+
assert.deepEqual(a.first, a.last);
831+
832+
set(b, 1);
833+
834+
flushSync();
835+
836+
assert.deepEqual(c!.children?.length, 1);
837+
assert.deepEqual(a.first, a.last);
838+
839+
destroy();
840+
841+
assert.deepEqual(a.deriveds, null);
842+
assert.deepEqual(a.first, null);
843+
};
844+
});
845+
806846
test('bigint states update correctly', () => {
807847
return () => {
808848
const count = state(0n);

0 commit comments

Comments
 (0)