svelte 5.57.1 → 5.57.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/index.js +1 -1
- package/package.json +1 -1
- package/src/compiler/errors.js +10 -0
- package/src/compiler/migrate/index.js +15 -4
- package/src/compiler/phases/1-parse/state/tag.js +2 -0
- package/src/compiler/phases/2-analyze/visitors/LetDirective.js +22 -0
- package/src/compiler/phases/2-analyze/visitors/shared/a11y/index.js +32 -7
- package/src/compiler/phases/3-transform/client/visitors/AwaitExpression.js +2 -1
- package/src/compiler/phases/3-transform/client/visitors/shared/events.js +3 -2
- package/src/compiler/phases/scope.js +8 -0
- package/src/compiler/print/index.js +3 -1
- package/src/index-client.js +1 -1
- package/src/internal/client/dev/debug.js +14 -0
- package/src/internal/client/dev/tracing.js +3 -1
- package/src/internal/client/dom/blocks/boundary.js +43 -15
- package/src/internal/client/dom/blocks/each.js +8 -6
- package/src/internal/client/dom/blocks/svelte-element.js +3 -1
- package/src/internal/client/dom/css.js +1 -1
- package/src/internal/client/dom/elements/attributes.js +178 -150
- package/src/internal/client/dom/elements/bindings/document.js +3 -2
- package/src/internal/client/dom/elements/transitions.js +3 -3
- package/src/internal/client/error-handling.js +5 -1
- package/src/internal/client/proxy.js +2 -1
- package/src/internal/client/reactivity/async.js +5 -0
- package/src/internal/client/reactivity/batch.js +82 -116
- package/src/internal/client/reactivity/deriveds.js +2 -1
- package/src/internal/client/reactivity/sources.js +5 -5
- package/src/internal/client/reactivity/utils.js +5 -6
- package/src/internal/client/runtime.js +13 -16
- package/src/internal/server/errors.js +2 -2
- package/src/internal/server/index.js +1 -1
- package/src/reactivity/date.js +2 -2
- package/src/reactivity/url-search-params.js +1 -1
- package/src/version.js +1 -1
- package/types/index.d.ts.map +1 -1
|
@@ -98,15 +98,15 @@ export class Batch {
|
|
|
98
98
|
id = uid++;
|
|
99
99
|
|
|
100
100
|
/** True as soon as `#process` was called */
|
|
101
|
-
|
|
101
|
+
started = false;
|
|
102
102
|
|
|
103
103
|
linked = true;
|
|
104
104
|
|
|
105
105
|
/** @type {Batch | null} */
|
|
106
|
-
|
|
106
|
+
prev = null;
|
|
107
107
|
|
|
108
108
|
/** @type {Batch | null} */
|
|
109
|
-
|
|
109
|
+
next = null;
|
|
110
110
|
|
|
111
111
|
/** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
|
|
112
112
|
async_deriveds = new Map();
|
|
@@ -114,14 +114,14 @@ export class Batch {
|
|
|
114
114
|
/**
|
|
115
115
|
* The current values of any signals that are updated in this batch.
|
|
116
116
|
* Tuple format: [value, is_derived] (note: is_derived is false for deriveds, too, if they were overridden via assignment)
|
|
117
|
-
*
|
|
117
|
+
* The keys of this map are identical to `this.previous`
|
|
118
118
|
* @type {Map<Value, [any, boolean]>}
|
|
119
119
|
*/
|
|
120
120
|
current = new Map();
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* The values of any signals (sources and deriveds) that are updated in this batch _before_ those updates took place.
|
|
124
|
-
*
|
|
124
|
+
* The keys of this map are identical to `this.current`
|
|
125
125
|
* @type {Map<Value, any>}
|
|
126
126
|
*/
|
|
127
127
|
previous = new Map();
|
|
@@ -177,16 +177,10 @@ export class Batch {
|
|
|
177
177
|
#new_effects = [];
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
|
-
* Deferred effects (which run after async work has completed)
|
|
181
|
-
* @type {
|
|
182
|
-
*/
|
|
183
|
-
#dirty_effects = new Set();
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Deferred effects that are MAYBE_DIRTY
|
|
187
|
-
* @type {Set<Effect>}
|
|
180
|
+
* Deferred effects (which run after async work has completed) and their status (DIRTY or MAYBE_DIRTY)
|
|
181
|
+
* @type {Map<Effect, number>}
|
|
188
182
|
*/
|
|
189
|
-
#
|
|
183
|
+
#dirty_reactions = new Map();
|
|
190
184
|
|
|
191
185
|
/**
|
|
192
186
|
* A map of branches that still exist, but will be destroyed when this batch
|
|
@@ -208,12 +202,11 @@ export class Batch {
|
|
|
208
202
|
#decrement_queued = false;
|
|
209
203
|
|
|
210
204
|
constructor() {
|
|
211
|
-
// link batch
|
|
212
205
|
if (last_batch === null) {
|
|
213
206
|
first_batch = last_batch = this;
|
|
214
207
|
} else {
|
|
215
|
-
last_batch
|
|
216
|
-
this
|
|
208
|
+
last_batch.next = this;
|
|
209
|
+
this.prev = last_batch;
|
|
217
210
|
}
|
|
218
211
|
|
|
219
212
|
last_batch = this;
|
|
@@ -223,19 +216,8 @@ export class Batch {
|
|
|
223
216
|
if (this.is_fork) return true;
|
|
224
217
|
|
|
225
218
|
for (const effect of this.#blocking_pending.keys()) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
while (e.parent !== null) {
|
|
230
|
-
if (this.#skipped_branches.has(e)) {
|
|
231
|
-
skipped = true;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
e = e.parent;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (!skipped) {
|
|
219
|
+
// pending work inside a skipped branch doesn't block, the branch is going to be destroyed
|
|
220
|
+
if (!this.#is_skipped(effect)) {
|
|
239
221
|
return true;
|
|
240
222
|
}
|
|
241
223
|
}
|
|
@@ -243,6 +225,18 @@ export class Batch {
|
|
|
243
225
|
return false;
|
|
244
226
|
}
|
|
245
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Whether `effect` is inside a branch that this batch skips
|
|
230
|
+
* @param {Effect} effect
|
|
231
|
+
*/
|
|
232
|
+
#is_skipped(effect) {
|
|
233
|
+
for (var e = /** @type {Effect | null} */ (effect); e !== null; e = e.parent) {
|
|
234
|
+
if (this.#skipped_branches.has(e)) return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
246
240
|
/**
|
|
247
241
|
* Add an effect to the #skipped_branches map and reset its children
|
|
248
242
|
* @param {Effect} effect
|
|
@@ -327,7 +321,7 @@ export class Batch {
|
|
|
327
321
|
}
|
|
328
322
|
|
|
329
323
|
#process() {
|
|
330
|
-
this
|
|
324
|
+
this.started = true;
|
|
331
325
|
|
|
332
326
|
if (DEV) {
|
|
333
327
|
// track all the values that were updated during this flush,
|
|
@@ -341,14 +335,8 @@ export class Batch {
|
|
|
341
335
|
// #is_deferred() is true, because traversing the tree could make
|
|
342
336
|
// an if block that contains the last blocking pending effect falsy,
|
|
343
337
|
// causing the block to no longer be deferred.
|
|
344
|
-
for (const e of this.#
|
|
345
|
-
|
|
346
|
-
set_signal_status(e, DIRTY);
|
|
347
|
-
this.schedule(e);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
for (const e of this.#maybe_dirty_effects) {
|
|
351
|
-
set_signal_status(e, MAYBE_DIRTY);
|
|
338
|
+
for (const [e, status] of this.#dirty_reactions) {
|
|
339
|
+
set_signal_status(e, status);
|
|
352
340
|
this.schedule(e);
|
|
353
341
|
}
|
|
354
342
|
|
|
@@ -432,8 +420,7 @@ export class Batch {
|
|
|
432
420
|
}
|
|
433
421
|
|
|
434
422
|
// clear effects. Those that are still needed will be rescheduled through unskipping the skipped branches.
|
|
435
|
-
this.#
|
|
436
|
-
this.#maybe_dirty_effects.clear();
|
|
423
|
+
this.#dirty_reactions.clear();
|
|
437
424
|
|
|
438
425
|
// append/remove branches
|
|
439
426
|
for (const fn of this.#commit_callbacks) fn(this);
|
|
@@ -462,21 +449,6 @@ export class Batch {
|
|
|
462
449
|
}
|
|
463
450
|
}
|
|
464
451
|
|
|
465
|
-
// Edge case: During traversal new branches might create effects that run immediately and set state,
|
|
466
|
-
// causing an effect to be scheduled again. We need to traverse the current batch
|
|
467
|
-
// once more in that case - most of the time this will just clean up dirty branches.
|
|
468
|
-
if (this.#scheduled.length > 0) {
|
|
469
|
-
if (next_batch !== null) {
|
|
470
|
-
for (const e of this.#scheduled) {
|
|
471
|
-
next_batch.#scheduled.push(e);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
this.#scheduled = [];
|
|
475
|
-
} else {
|
|
476
|
-
next_batch = this;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
452
|
if (next_batch !== null) {
|
|
481
453
|
old_values.clear();
|
|
482
454
|
next_batch.#process();
|
|
@@ -510,7 +482,7 @@ export class Batch {
|
|
|
510
482
|
} else if (async_mode_flag && (flags & (RENDER_EFFECT | MANAGED_EFFECT)) !== 0) {
|
|
511
483
|
render_effects.push(effect);
|
|
512
484
|
} else if (is_dirty(effect)) {
|
|
513
|
-
if ((flags & BLOCK_EFFECT) !== 0) this
|
|
485
|
+
if ((flags & BLOCK_EFFECT) !== 0) this.add_dirty_reaction(effect, MAYBE_DIRTY);
|
|
514
486
|
update_effect(effect);
|
|
515
487
|
}
|
|
516
488
|
|
|
@@ -536,24 +508,23 @@ export class Batch {
|
|
|
536
508
|
}
|
|
537
509
|
|
|
538
510
|
#find_earlier_batch() {
|
|
539
|
-
var batch = this
|
|
540
|
-
|
|
541
|
-
while (batch !== null) {
|
|
542
|
-
if (!batch.is_fork) {
|
|
543
|
-
// if the batches are connected, break
|
|
544
|
-
for (const [value, [, is_derived]] of this.current) {
|
|
545
|
-
if (batch.current.has(value) && !is_derived) {
|
|
546
|
-
return batch;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
batch = batch.#prev;
|
|
511
|
+
for (var batch = this.prev; batch !== null; batch = batch.prev) {
|
|
512
|
+
if (!batch.is_fork && this.#intersects(batch)) return batch;
|
|
552
513
|
}
|
|
553
514
|
|
|
554
515
|
return null;
|
|
555
516
|
}
|
|
556
517
|
|
|
518
|
+
/** @param {Batch} batch */
|
|
519
|
+
#intersects(batch) {
|
|
520
|
+
for (const [source, [, is_derived]] of this.current) {
|
|
521
|
+
if (is_derived) continue;
|
|
522
|
+
if (batch.current.has(source)) return true;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
|
|
557
528
|
/**
|
|
558
529
|
* @param {Batch} batch
|
|
559
530
|
*/
|
|
@@ -576,7 +547,7 @@ export class Batch {
|
|
|
576
547
|
batch.async_deriveds.clear();
|
|
577
548
|
|
|
578
549
|
// Mark is not guaranteed not touch these, so we transfer them
|
|
579
|
-
this.
|
|
550
|
+
this.transfer_reactions(batch.#dirty_reactions);
|
|
580
551
|
|
|
581
552
|
/**
|
|
582
553
|
* mark all effects that depend on `batch.current`, except the
|
|
@@ -605,7 +576,7 @@ export class Batch {
|
|
|
605
576
|
var effect = /** @type {Effect} */ (reaction);
|
|
606
577
|
|
|
607
578
|
if (flags & (ASYNC | BLOCK_EFFECT) && !this.async_deriveds.has(effect)) {
|
|
608
|
-
this.#
|
|
579
|
+
this.#dirty_reactions.delete(effect);
|
|
609
580
|
set_signal_status(effect, DIRTY);
|
|
610
581
|
this.schedule(effect);
|
|
611
582
|
}
|
|
@@ -629,7 +600,7 @@ export class Batch {
|
|
|
629
600
|
*/
|
|
630
601
|
#defer_effects(effects) {
|
|
631
602
|
for (var i = 0; i < effects.length; i += 1) {
|
|
632
|
-
defer_effect(effects[i], this.#
|
|
603
|
+
defer_effect(effects[i], this.#dirty_reactions);
|
|
633
604
|
}
|
|
634
605
|
}
|
|
635
606
|
|
|
@@ -719,7 +690,7 @@ export class Batch {
|
|
|
719
690
|
// in other words, we re-run block/async effects with the newly
|
|
720
691
|
// committed state, unless the batch in question has a more
|
|
721
692
|
// recent value for a given source
|
|
722
|
-
for (let batch = first_batch; batch !== null; batch = batch
|
|
693
|
+
for (let batch = first_batch; batch !== null; batch = batch.next) {
|
|
723
694
|
var is_earlier = batch.id < this.id;
|
|
724
695
|
|
|
725
696
|
/** @type {Source[]} */
|
|
@@ -756,7 +727,7 @@ export class Batch {
|
|
|
756
727
|
);
|
|
757
728
|
|
|
758
729
|
// If not started yet or no sources to update (which is e.g. possible for the very first batch) then bail
|
|
759
|
-
if (!batch
|
|
730
|
+
if (!batch.started || current.length === 0) continue;
|
|
760
731
|
|
|
761
732
|
// Re-run async/block effects that depend on distinct values changed in both batches (ignoring deriveds)
|
|
762
733
|
var others = current.filter((source) => !this.current.has(source));
|
|
@@ -818,7 +789,7 @@ export class Batch {
|
|
|
818
789
|
set_signal_status(effect, DIRTY);
|
|
819
790
|
batch.schedule(effect);
|
|
820
791
|
} else {
|
|
821
|
-
batch
|
|
792
|
+
batch.add_dirty_reaction(effect, DIRTY);
|
|
822
793
|
}
|
|
823
794
|
}
|
|
824
795
|
}
|
|
@@ -882,20 +853,24 @@ export class Batch {
|
|
|
882
853
|
}
|
|
883
854
|
|
|
884
855
|
/**
|
|
885
|
-
* @param {
|
|
886
|
-
* @param {Set<Effect>} maybe_dirty_effects
|
|
856
|
+
* @param {Map<Effect, number>} dirty_reactions
|
|
887
857
|
*/
|
|
888
|
-
|
|
889
|
-
for (const
|
|
890
|
-
this
|
|
858
|
+
transfer_reactions(dirty_reactions) {
|
|
859
|
+
for (const [effect, status] of dirty_reactions) {
|
|
860
|
+
this.add_dirty_reaction(effect, status);
|
|
891
861
|
}
|
|
892
862
|
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
}
|
|
863
|
+
dirty_reactions.clear();
|
|
864
|
+
}
|
|
896
865
|
|
|
897
|
-
|
|
898
|
-
|
|
866
|
+
/**
|
|
867
|
+
* @param {Effect} effect
|
|
868
|
+
* @param {number} status
|
|
869
|
+
*/
|
|
870
|
+
add_dirty_reaction(effect, status) {
|
|
871
|
+
if (status === DIRTY || this.#dirty_reactions.get(effect) !== DIRTY) {
|
|
872
|
+
this.#dirty_reactions.set(effect, status);
|
|
873
|
+
}
|
|
899
874
|
}
|
|
900
875
|
|
|
901
876
|
/** @param {(batch: Batch) => void} fn */
|
|
@@ -918,7 +893,7 @@ export class Batch {
|
|
|
918
893
|
|
|
919
894
|
if (!is_processing && !is_flushing_sync) {
|
|
920
895
|
queue_micro_task(() => {
|
|
921
|
-
if (!batch
|
|
896
|
+
if (!batch.started) {
|
|
922
897
|
batch.flush();
|
|
923
898
|
}
|
|
924
899
|
});
|
|
@@ -929,7 +904,7 @@ export class Batch {
|
|
|
929
904
|
}
|
|
930
905
|
|
|
931
906
|
apply() {
|
|
932
|
-
if (!async_mode_flag || (!this.is_fork && this
|
|
907
|
+
if (!async_mode_flag || (!this.is_fork && this.prev === null && this.next === null)) {
|
|
933
908
|
batch_values = null;
|
|
934
909
|
return;
|
|
935
910
|
}
|
|
@@ -942,32 +917,15 @@ export class Batch {
|
|
|
942
917
|
}
|
|
943
918
|
|
|
944
919
|
// ...and undo changes belonging to other batches unless they intersect
|
|
945
|
-
for (let batch = first_batch; batch !== null; batch = batch
|
|
920
|
+
for (let batch = first_batch; batch !== null; batch = batch.next) {
|
|
946
921
|
if (batch === this || batch.is_fork) continue;
|
|
947
922
|
|
|
948
|
-
// If two batches intersect, the latter batch will be merged into the earlier batch,
|
|
949
|
-
// and we should treat them as a single set of changes
|
|
950
|
-
var intersects = false;
|
|
951
|
-
|
|
952
|
-
if (batch.id < this.id) {
|
|
953
|
-
for (const [source, [, is_derived]] of batch.current) {
|
|
954
|
-
// Derived values don't partake in the intersection mechanism, because a derived could
|
|
955
|
-
// be triggered in one batch already but not the other one yet, causing a false-positive
|
|
956
|
-
if (is_derived) continue;
|
|
957
|
-
|
|
958
|
-
if (this.current.has(source)) {
|
|
959
|
-
intersects = true;
|
|
960
|
-
break;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
923
|
// Since the latter batch merges into the earlier (if it resolves before the earlier one),
|
|
966
924
|
// we treat the earlier values as "already applied". This way we don't need to rerun async
|
|
967
925
|
// effects of the earlier batch in case they are merged.
|
|
968
926
|
// As a result you can think of batch_values as having the latest values of all intersecting
|
|
969
927
|
// batches up until this batch.
|
|
970
|
-
if (!intersects) {
|
|
928
|
+
if (batch.id >= this.id || !batch.#intersects(this)) {
|
|
971
929
|
for (const [source, previous] of batch.previous) {
|
|
972
930
|
if (!batch_values.has(source)) {
|
|
973
931
|
batch_values.set(source, previous);
|
|
@@ -1003,19 +961,19 @@ export class Batch {
|
|
|
1003
961
|
// running it multiple times to not corrupt the linked list
|
|
1004
962
|
if (!this.linked) return;
|
|
1005
963
|
|
|
1006
|
-
var prev = this
|
|
1007
|
-
var next = this
|
|
964
|
+
var prev = this.prev;
|
|
965
|
+
var next = this.next;
|
|
1008
966
|
|
|
1009
967
|
if (prev === null) {
|
|
1010
968
|
first_batch = next;
|
|
1011
969
|
} else {
|
|
1012
|
-
prev
|
|
970
|
+
prev.next = next;
|
|
1013
971
|
}
|
|
1014
972
|
|
|
1015
973
|
if (next === null) {
|
|
1016
974
|
last_batch = prev;
|
|
1017
975
|
} else {
|
|
1018
|
-
next
|
|
976
|
+
next.prev = prev;
|
|
1019
977
|
}
|
|
1020
978
|
|
|
1021
979
|
this.linked = false;
|
|
@@ -1032,15 +990,15 @@ export class Batch {
|
|
|
1032
990
|
*/
|
|
1033
991
|
export function flushSync(fn) {
|
|
1034
992
|
var was_flushing_sync = is_flushing_sync;
|
|
993
|
+
var prev_previous_batch = previous_batch;
|
|
994
|
+
previous_batch = null;
|
|
1035
995
|
is_flushing_sync = true;
|
|
1036
996
|
|
|
1037
997
|
try {
|
|
1038
998
|
var result;
|
|
1039
999
|
|
|
1040
1000
|
if (fn) {
|
|
1041
|
-
|
|
1042
|
-
current_batch.flush();
|
|
1043
|
-
}
|
|
1001
|
+
flushSync(); // flush anything pending through the while loop below
|
|
1044
1002
|
|
|
1045
1003
|
result = fn();
|
|
1046
1004
|
}
|
|
@@ -1056,6 +1014,7 @@ export function flushSync(fn) {
|
|
|
1056
1014
|
}
|
|
1057
1015
|
} finally {
|
|
1058
1016
|
is_flushing_sync = was_flushing_sync;
|
|
1017
|
+
previous_batch = prev_previous_batch;
|
|
1059
1018
|
}
|
|
1060
1019
|
}
|
|
1061
1020
|
|
|
@@ -1295,6 +1254,10 @@ export function eager(fn) {
|
|
|
1295
1254
|
let version = version_map.get(parent) ?? source(0);
|
|
1296
1255
|
version_map.set(parent, version);
|
|
1297
1256
|
|
|
1257
|
+
if (DEV) {
|
|
1258
|
+
version.label ??= '$state.eager version';
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1298
1261
|
teardown(() => {
|
|
1299
1262
|
if (parent.f & DESTROYING) version_map.delete(parent);
|
|
1300
1263
|
});
|
|
@@ -1402,6 +1365,8 @@ export function fork(fn) {
|
|
|
1402
1365
|
e.fork_timing();
|
|
1403
1366
|
}
|
|
1404
1367
|
|
|
1368
|
+
flushSync();
|
|
1369
|
+
|
|
1405
1370
|
var batch = Batch.ensure();
|
|
1406
1371
|
batch.is_fork = true;
|
|
1407
1372
|
batch_values = new Map();
|
|
@@ -1409,7 +1374,8 @@ export function fork(fn) {
|
|
|
1409
1374
|
var committed = false;
|
|
1410
1375
|
var settled = batch.settled();
|
|
1411
1376
|
|
|
1412
|
-
|
|
1377
|
+
fn();
|
|
1378
|
+
flushSync();
|
|
1413
1379
|
|
|
1414
1380
|
return {
|
|
1415
1381
|
commit: async () => {
|
|
@@ -1454,7 +1420,7 @@ export function fork(fn) {
|
|
|
1454
1420
|
},
|
|
1455
1421
|
discard: () => {
|
|
1456
1422
|
// cause any MAYBE_DIRTY deriveds to update
|
|
1457
|
-
// if they depend on things
|
|
1423
|
+
// if they depend on things that changed
|
|
1458
1424
|
// inside the discarded fork
|
|
1459
1425
|
for (var source of batch.current.keys()) {
|
|
1460
1426
|
source.wv = increment_write_version();
|
|
@@ -47,6 +47,7 @@ import { batch_values, current_batch, previous_batch } from './batch.js';
|
|
|
47
47
|
import { increment_pending, unset_context } from './async.js';
|
|
48
48
|
import { deferred, includes, noop } from '../../shared/utils.js';
|
|
49
49
|
import { set_signal_status, update_derived_status } from './status.js';
|
|
50
|
+
import { stringify_derived } from '../dev/debug.js';
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* This allows us to track 'reactivity loss' that occurs when signals
|
|
@@ -120,7 +121,7 @@ export function async_derived(fn, label, location) {
|
|
|
120
121
|
var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined));
|
|
121
122
|
var signal = source(/** @type {V} */ (UNINITIALIZED));
|
|
122
123
|
|
|
123
|
-
if (DEV) signal.label = label ?? fn
|
|
124
|
+
if (DEV) signal.label = label ?? stringify_derived(fn);
|
|
124
125
|
|
|
125
126
|
// only suspend in async deriveds created on initialisation
|
|
126
127
|
var should_suspend = !active_reaction;
|
|
@@ -46,7 +46,7 @@ import { set_signal_status, update_derived_status } from './status.js';
|
|
|
46
46
|
/** @type {Set<Effect>} */
|
|
47
47
|
export let eager_effects = new Set();
|
|
48
48
|
|
|
49
|
-
/** @type {Map<
|
|
49
|
+
/** @type {Map<Value, any>} */
|
|
50
50
|
export const old_values = new Map();
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -70,9 +70,9 @@ export function set_eager_effects_deferred() {
|
|
|
70
70
|
*/
|
|
71
71
|
// TODO rename this to `state` throughout the codebase
|
|
72
72
|
export function source(v, stack) {
|
|
73
|
-
/** @type {
|
|
73
|
+
/** @type {Source<V>} */
|
|
74
74
|
var signal = {
|
|
75
|
-
f: 0,
|
|
75
|
+
f: 0,
|
|
76
76
|
v,
|
|
77
77
|
reactions: null,
|
|
78
78
|
equals,
|
|
@@ -141,7 +141,7 @@ export function mutate(source, value) {
|
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
* @template V
|
|
144
|
-
* @param {
|
|
144
|
+
* @param {Value<V>} source
|
|
145
145
|
* @param {V} value
|
|
146
146
|
* @param {boolean} [should_proxy]
|
|
147
147
|
* @returns {V}
|
|
@@ -181,7 +181,7 @@ var count_deps = 0;
|
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
183
|
* @template V
|
|
184
|
-
* @param {
|
|
184
|
+
* @param {Value<V>} source
|
|
185
185
|
* @param {V} value
|
|
186
186
|
* @param {Effect[] | null} [updated_during_traversal]
|
|
187
187
|
* @returns {V}
|
|
@@ -4,14 +4,13 @@ import { set_signal_status } from './status.js';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {Effect} effect
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {Set<Effect>} maybe_dirty_effects
|
|
7
|
+
* @param {Map<Effect, number>} dirty_reactions
|
|
9
8
|
*/
|
|
10
|
-
export function defer_effect(effect,
|
|
9
|
+
export function defer_effect(effect, dirty_reactions) {
|
|
11
10
|
if ((effect.f & DIRTY) !== 0) {
|
|
12
|
-
|
|
13
|
-
} else if ((effect.f & MAYBE_DIRTY) !== 0) {
|
|
14
|
-
|
|
11
|
+
dirty_reactions.set(effect, DIRTY);
|
|
12
|
+
} else if ((effect.f & MAYBE_DIRTY) !== 0 && dirty_reactions.get(effect) !== DIRTY) {
|
|
13
|
+
dirty_reactions.set(effect, MAYBE_DIRTY);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
// mark as clean so they get scheduled if they depend on pending async state
|
|
@@ -60,11 +60,6 @@ import { without_reactive_context } from './dom/elements/bindings/shared.js';
|
|
|
60
60
|
import { set_signal_status, update_derived_status } from './reactivity/status.js';
|
|
61
61
|
import * as w from './warnings.js';
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* True if updating in an effect context that is reactive (i.e. not branch/root effects)
|
|
65
|
-
*/
|
|
66
|
-
let is_updating_effect = false;
|
|
67
|
-
|
|
68
63
|
export let is_destroying_effect = false;
|
|
69
64
|
|
|
70
65
|
/** @param {boolean} value */
|
|
@@ -93,7 +88,7 @@ export function set_active_effect(effect) {
|
|
|
93
88
|
/**
|
|
94
89
|
* When sources are created within a reaction, reading and writing
|
|
95
90
|
* them within that reaction should not cause a re-run
|
|
96
|
-
* @type {null | Set<
|
|
91
|
+
* @type {null | Set<Value>}
|
|
97
92
|
*/
|
|
98
93
|
export let current_sources = null;
|
|
99
94
|
|
|
@@ -121,11 +116,11 @@ export let skipped_deps = 0;
|
|
|
121
116
|
/**
|
|
122
117
|
* Tracks writes that the effect it's executed in doesn't listen to yet,
|
|
123
118
|
* so that the dependency can be added to the effect later on if it then reads it
|
|
124
|
-
* @type {null |
|
|
119
|
+
* @type {null | Value[]}
|
|
125
120
|
*/
|
|
126
121
|
export let untracked_writes = null;
|
|
127
122
|
|
|
128
|
-
/** @param {null |
|
|
123
|
+
/** @param {null | Value[]} value */
|
|
129
124
|
export function set_untracked_writes(value) {
|
|
130
125
|
untracked_writes = value;
|
|
131
126
|
}
|
|
@@ -410,7 +405,7 @@ function remove_reaction(signal, dependency) {
|
|
|
410
405
|
// In a fork it's possible that a derived is executed and gets reactions, then commits, but is
|
|
411
406
|
// never re-executed. This is possible when the derived is only executed once in the context
|
|
412
407
|
// of a new branch which happens before fork.commit() runs. In this case, the derived still has
|
|
413
|
-
// UNINITIALIZED as its value, and then when it's
|
|
408
|
+
// UNINITIALIZED as its value, and then when it's losing its reactions we need to ensure it stays
|
|
414
409
|
// DIRTY so it is reexecuted once someone wants its value again.
|
|
415
410
|
if (derived.v !== UNINITIALIZED) {
|
|
416
411
|
update_derived_status(derived);
|
|
@@ -462,10 +457,8 @@ export function update_effect(effect) {
|
|
|
462
457
|
set_signal_status(effect, CLEAN);
|
|
463
458
|
|
|
464
459
|
var previous_effect = active_effect;
|
|
465
|
-
var was_updating_effect = is_updating_effect;
|
|
466
460
|
|
|
467
461
|
active_effect = effect;
|
|
468
|
-
is_updating_effect = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0; // Branch/root effects are not reactive contexts
|
|
469
462
|
|
|
470
463
|
if (DEV) {
|
|
471
464
|
var previous_component_fn = dev_current_component_function;
|
|
@@ -498,7 +491,6 @@ export function update_effect(effect) {
|
|
|
498
491
|
}
|
|
499
492
|
}
|
|
500
493
|
} finally {
|
|
501
|
-
is_updating_effect = was_updating_effect;
|
|
502
494
|
active_effect = previous_effect;
|
|
503
495
|
|
|
504
496
|
if (DEV) {
|
|
@@ -680,13 +672,12 @@ export function get(signal) {
|
|
|
680
672
|
return value;
|
|
681
673
|
}
|
|
682
674
|
|
|
683
|
-
// connect disconnected deriveds
|
|
684
|
-
// or inside another derived that is already connected
|
|
675
|
+
// connect disconnected deriveds when reading them inside a connected reaction
|
|
685
676
|
var should_connect =
|
|
686
677
|
(derived.f & CONNECTED) === 0 &&
|
|
687
678
|
!untracking &&
|
|
688
679
|
active_reaction !== null &&
|
|
689
|
-
(
|
|
680
|
+
(active_reaction.f & CONNECTED) !== 0;
|
|
690
681
|
|
|
691
682
|
var is_new = (derived.f & REACTION_RAN) === 0;
|
|
692
683
|
|
|
@@ -728,7 +719,13 @@ function reconnect(derived) {
|
|
|
728
719
|
if (derived.deps === null) return;
|
|
729
720
|
|
|
730
721
|
for (const dep of derived.deps) {
|
|
731
|
-
|
|
722
|
+
var reactions = dep.reactions;
|
|
723
|
+
|
|
724
|
+
if (reactions === null) {
|
|
725
|
+
dep.reactions = [derived];
|
|
726
|
+
} else if (!includes.call(reactions, derived)) {
|
|
727
|
+
reactions.push(derived);
|
|
728
|
+
}
|
|
732
729
|
|
|
733
730
|
if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {
|
|
734
731
|
unfreeze_derived_effects(/** @type {Derived} */ (dep));
|
|
@@ -72,7 +72,7 @@ ${stack}\nhttps://svelte.dev/e/hydratable_clobbering`);
|
|
|
72
72
|
/**
|
|
73
73
|
* Failed to serialize `hydratable` data for key `%key%`.
|
|
74
74
|
*
|
|
75
|
-
* `hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/
|
|
75
|
+
* `hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/devalue) can, plus Promises.
|
|
76
76
|
*
|
|
77
77
|
* Cause:
|
|
78
78
|
* %stack%
|
|
@@ -83,7 +83,7 @@ ${stack}\nhttps://svelte.dev/e/hydratable_clobbering`);
|
|
|
83
83
|
export function hydratable_serialization_failed(key, stack) {
|
|
84
84
|
const error = new Error(`hydratable_serialization_failed\nFailed to serialize \`hydratable\` data for key \`${key}\`.
|
|
85
85
|
|
|
86
|
-
\`hydratable\` can serialize anything [\`uneval\` from \`devalue\`](https://npmjs.com/package/
|
|
86
|
+
\`hydratable\` can serialize anything [\`uneval\` from \`devalue\`](https://npmjs.com/package/devalue) can, plus Promises.
|
|
87
87
|
|
|
88
88
|
Cause:
|
|
89
89
|
${stack}\nhttps://svelte.dev/e/hydratable_serialization_failed`);
|
|
@@ -168,7 +168,7 @@ export function attributes(attrs, css_hash, classes, styles, flags = 0) {
|
|
|
168
168
|
// value/checked takes precedence over defaultValue/defaultChecked
|
|
169
169
|
name = name === 'defaultvalue' ? 'value' : 'checked';
|
|
170
170
|
if (name in attrs) continue;
|
|
171
|
-
// We're checking prior entries
|
|
171
|
+
// We're checking prior entries as well because "name in attrs" is not enough as the attributes may have different casing
|
|
172
172
|
for (let j = 0; j < names.length; j++) {
|
|
173
173
|
if (names[j].toLowerCase() === name) continue outer;
|
|
174
174
|
}
|
package/src/reactivity/date.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @import {
|
|
1
|
+
/** @import { Derived } from '#client' */
|
|
2
2
|
import { derived } from '../internal/client/index.js';
|
|
3
3
|
import { set, state } from '../internal/client/reactivity/sources.js';
|
|
4
4
|
import { tag } from '../internal/client/dev/tracing.js';
|
|
@@ -42,7 +42,7 @@ var inited = false;
|
|
|
42
42
|
export class SvelteDate extends Date {
|
|
43
43
|
#time = state(super.getTime());
|
|
44
44
|
|
|
45
|
-
/** @type {Map<keyof Date,
|
|
45
|
+
/** @type {Map<keyof Date, Derived<unknown>>} */
|
|
46
46
|
#deriveds = new Map();
|
|
47
47
|
|
|
48
48
|
#reaction = active_reaction;
|
|
@@ -42,7 +42,7 @@ export class SvelteURLSearchParams extends URLSearchParams {
|
|
|
42
42
|
if (!this.#url || this.#updating) return;
|
|
43
43
|
this.#updating = true;
|
|
44
44
|
|
|
45
|
-
const search =
|
|
45
|
+
const search = super.toString();
|
|
46
46
|
this.#url.search = search && `?${search}`;
|
|
47
47
|
|
|
48
48
|
this.#updating = false;
|
package/src/version.js
CHANGED