svelte 5.58.0 → 5.59.0

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.
Files changed (100) hide show
  1. package/compiler/index.js +1 -1
  2. package/package.json +19 -1
  3. package/renderer.d.ts +1 -0
  4. package/src/compiler/errors.js +19 -0
  5. package/src/compiler/index.js +37 -2
  6. package/src/compiler/migrate/index.js +2 -1
  7. package/src/compiler/phases/1-parse/read/options.js +20 -0
  8. package/src/compiler/phases/2-analyze/index.js +21 -2
  9. package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +5 -0
  10. package/src/compiler/phases/2-analyze/visitors/Attribute.js +6 -2
  11. package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -0
  12. package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +2 -1
  13. package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +5 -0
  14. package/src/compiler/phases/2-analyze/visitors/OnDirective.js +6 -0
  15. package/src/compiler/phases/2-analyze/visitors/RegularElement.js +13 -6
  16. package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +5 -0
  17. package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +5 -0
  18. package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +5 -1
  19. package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +5 -0
  20. package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +5 -0
  21. package/src/compiler/phases/2-analyze/visitors/Text.js +3 -1
  22. package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +6 -0
  23. package/src/compiler/phases/2-analyze/visitors/shared/element.js +3 -2
  24. package/src/compiler/phases/3-transform/client/transform-client.js +68 -1
  25. package/src/compiler/phases/3-transform/client/transform-template/index.js +4 -3
  26. package/src/compiler/phases/3-transform/client/transform-template/template.js +1 -1
  27. package/src/compiler/phases/3-transform/client/utils.js +3 -2
  28. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +23 -13
  29. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +13 -1
  30. package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +11 -1
  31. package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +8 -5
  32. package/src/compiler/phases/3-transform/client/visitors/shared/component.js +17 -8
  33. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +4 -3
  34. package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +7 -1
  35. package/src/compiler/phases/3-transform/server/transform-server.js +14 -1
  36. package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +8 -0
  37. package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +8 -4
  38. package/src/compiler/print/index.js +45 -57
  39. package/src/compiler/state.js +12 -0
  40. package/src/compiler/utils/builders.js +2 -2
  41. package/src/compiler/validate-options.js +47 -1
  42. package/src/index-client.js +3 -3
  43. package/src/internal/client/constants.js +15 -1
  44. package/src/internal/client/custom-renderer/containers.js +213 -0
  45. package/src/internal/client/custom-renderer/cross.js +145 -0
  46. package/src/internal/client/custom-renderer/index.js +28 -0
  47. package/src/internal/client/custom-renderer/state.js +59 -0
  48. package/src/internal/client/dev/css.js +3 -1
  49. package/src/internal/client/dev/debug.js +6 -6
  50. package/src/internal/client/dev/elements.js +9 -7
  51. package/src/internal/client/dev/tracing.js +67 -11
  52. package/src/internal/client/dev/validation.js +2 -1
  53. package/src/internal/client/dom/blocks/async.js +2 -1
  54. package/src/internal/client/dom/blocks/await.js +110 -19
  55. package/src/internal/client/dom/blocks/boundary.js +142 -88
  56. package/src/internal/client/dom/blocks/branches.js +94 -75
  57. package/src/internal/client/dom/blocks/css-props.js +31 -3
  58. package/src/internal/client/dom/blocks/each.js +166 -45
  59. package/src/internal/client/dom/blocks/html.js +19 -13
  60. package/src/internal/client/dom/blocks/slot.js +3 -3
  61. package/src/internal/client/dom/blocks/snippet.js +52 -3
  62. package/src/internal/client/dom/blocks/svelte-element.js +17 -6
  63. package/src/internal/client/dom/blocks/svelte-head.js +13 -4
  64. package/src/internal/client/dom/css.js +4 -4
  65. package/src/internal/client/dom/elements/attributes.js +91 -51
  66. package/src/internal/client/dom/elements/bindings/input.js +19 -10
  67. package/src/internal/client/dom/elements/bindings/select.js +13 -9
  68. package/src/internal/client/dom/elements/class.js +16 -5
  69. package/src/internal/client/dom/elements/events.js +153 -21
  70. package/src/internal/client/dom/elements/misc.js +3 -2
  71. package/src/internal/client/dom/elements/style.js +17 -6
  72. package/src/internal/client/dom/hydration.js +6 -6
  73. package/src/internal/client/dom/operations.js +435 -14
  74. package/src/internal/client/dom/reconciler.js +2 -2
  75. package/src/internal/client/dom/template.js +94 -66
  76. package/src/internal/client/error-handling.js +4 -12
  77. package/src/internal/client/errors.js +85 -2
  78. package/src/internal/client/index.js +9 -2
  79. package/src/internal/client/reactivity/async.js +257 -122
  80. package/src/internal/client/reactivity/batch.js +1124 -531
  81. package/src/internal/client/reactivity/deriveds.js +281 -177
  82. package/src/internal/client/reactivity/effects.js +87 -54
  83. package/src/internal/client/reactivity/sources.js +30 -124
  84. package/src/internal/client/reactivity/status.js +1 -1
  85. package/src/internal/client/render.js +60 -87
  86. package/src/internal/client/runtime.js +931 -153
  87. package/src/internal/client/validate.js +2 -2
  88. package/src/internal/disclose-version.js +1 -1
  89. package/src/internal/flags/custom-renderer-server.js +10 -0
  90. package/src/internal/flags/custom-renderer.js +3 -0
  91. package/src/internal/flags/index.js +6 -0
  92. package/src/internal/init-operations.js +3 -0
  93. package/src/internal/shared/errors.js +20 -0
  94. package/src/legacy/legacy-client.js +6 -2
  95. package/src/renderer/index-server.js +18 -0
  96. package/src/renderer/index.js +2 -0
  97. package/src/version.js +1 -1
  98. package/types/index.d.ts +245 -25
  99. package/types/index.d.ts.map +10 -1
  100. package/src/internal/client/reactivity/utils.js +0 -18
@@ -1,4 +1,5 @@
1
- /** @import { Blocker, ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */
1
+ /** @import { ComponentContext, ComponentContextLegacy, Derived, Effect, TemplateNode, TransitionManager } from '#client' */
2
+ /** @import { Blocker } from './async.js' */
2
3
  import {
3
4
  is_dirty,
4
5
  active_effect,
@@ -9,9 +10,11 @@ import {
9
10
  remove_reactions,
10
11
  set_active_reaction,
11
12
  set_is_destroying_effect,
13
+ teardown_version,
12
14
  untrack,
13
15
  untracking,
14
- set_active_effect
16
+ set_active_effect,
17
+ abort_all
15
18
  } from '../runtime.js';
16
19
  import {
17
20
  DIRTY,
@@ -29,7 +32,6 @@ import {
29
32
  HEAD_EFFECT,
30
33
  MAYBE_DIRTY,
31
34
  EFFECT_PRESERVED,
32
- STALE_REACTION,
33
35
  USER_EFFECT,
34
36
  ASYNC,
35
37
  CONNECTED,
@@ -41,12 +43,13 @@ import { invoke_error_boundary } from '../error-handling.js';
41
43
  import * as e from '../errors.js';
42
44
  import { DEV } from 'esm-env';
43
45
  import { define_property } from '../../shared/utils.js';
44
- import { get_next_sibling } from '../dom/operations.js';
46
+ import { get_next_sibling, remove_node, append_child } from '../dom/operations.js';
45
47
  import { component_context, dev_current_component_function, dev_stack } from '../context.js';
46
- import { Batch, collected_effects, current_batch } from './batch.js';
48
+ import { Batch, collected_effects, set_teardown_context, teardown_context } from './batch.js';
47
49
  import { flatten } from './async.js';
48
- import { without_reactive_context } from '../dom/elements/bindings/shared.js';
49
50
  import { set_signal_status } from './status.js';
51
+ import { push_renderer, current_renderer, pop_renderer } from '../custom-renderer/state.js';
52
+ import { custom_renderers_flag } from '../../flags/index.js';
50
53
 
51
54
  /**
52
55
  * @param {'$effect' | '$effect.pre' | '$inspect'} rune
@@ -103,6 +106,8 @@ function create_effect(type, fn) {
103
106
  var effect = {
104
107
  ctx: component_context,
105
108
  deps: null,
109
+ dv: null,
110
+ edges: null,
106
111
  nodes: null,
107
112
  f: type | DIRTY | CONNECTED,
108
113
  first: null,
@@ -114,15 +119,14 @@ function create_effect(type, fn) {
114
119
  prev: null,
115
120
  teardown: null,
116
121
  wv: 0,
117
- ac: null
122
+ ac: null,
123
+ r: current_renderer
118
124
  };
119
125
 
120
126
  if (DEV) {
121
127
  effect.component_function = dev_current_component_function;
122
128
  }
123
129
 
124
- current_batch?.register_created_effect(effect);
125
-
126
130
  /** @type {Effect | null} */
127
131
  var e = effect;
128
132
 
@@ -132,7 +136,7 @@ function create_effect(type, fn) {
132
136
  collected_effects.push(effect);
133
137
  } else {
134
138
  // schedule for later
135
- Batch.ensure().schedule(effect);
139
+ Batch.ensure().schedule(effect, DIRTY);
136
140
  }
137
141
  } else if (fn !== null) {
138
142
  try {
@@ -146,7 +150,7 @@ function create_effect(type, fn) {
146
150
  // won't re-run, has no DOM, and has no teardown etc)
147
151
  // then we skip it and go to its child (if any)
148
152
  if (
149
- e.deps === null &&
153
+ e.edges === null &&
150
154
  e.teardown === null &&
151
155
  e.nodes === null &&
152
156
  e.first === e.last && // either `null`, or a singular child
@@ -352,7 +356,7 @@ export function legacy_pre_effect_reset() {
352
356
 
353
357
  // If the effect is CLEAN, then make it MAYBE_DIRTY. This ensures we traverse through
354
358
  // the effects dependencies and correctly ensure each dependency is up-to-date.
355
- if ((effect.f & CLEAN) !== 0 && effect.deps !== null) {
359
+ if ((effect.f & CLEAN) !== 0 && effect.edges !== null) {
356
360
  set_signal_status(effect, MAYBE_DIRTY);
357
361
  }
358
362
 
@@ -446,6 +450,8 @@ export function execute_effect_teardown(effect) {
446
450
  var teardown = effect.teardown;
447
451
  if (teardown !== null) {
448
452
  const previously_destroying_effect = is_destroying_effect;
453
+ const previous_teardown_version = teardown_version;
454
+ const previous_teardown_context = teardown_context;
449
455
  const previous_reaction = active_reaction;
450
456
  set_is_destroying_effect(true);
451
457
  set_active_reaction(null);
@@ -457,7 +463,8 @@ export function execute_effect_teardown(effect) {
457
463
  // themselves mid-teardown are skipped by invoke_error_boundary.
458
464
  invoke_error_boundary(error, effect.parent);
459
465
  } finally {
460
- set_is_destroying_effect(previously_destroying_effect);
466
+ set_is_destroying_effect(previously_destroying_effect, previous_teardown_version);
467
+ set_teardown_context(previous_teardown_context);
461
468
  set_active_reaction(previous_reaction);
462
469
  }
463
470
  }
@@ -473,13 +480,7 @@ export function destroy_effect_children(signal, remove_dom = false) {
473
480
  signal.first = signal.last = null;
474
481
 
475
482
  while (effect !== null) {
476
- const controller = effect.ac;
477
-
478
- if (controller !== null) {
479
- without_reactive_context(() => {
480
- controller.abort(STALE_REACTION);
481
- });
482
- }
483
+ abort_all(effect);
483
484
 
484
485
  var next = effect.next;
485
486
 
@@ -518,28 +519,35 @@ export function destroy_block_effect_children(signal) {
518
519
  export function destroy_effect(effect, remove_dom = true) {
519
520
  var removed = false;
520
521
 
521
- if (
522
- (remove_dom || (effect.f & HEAD_EFFECT) !== 0) &&
523
- effect.nodes !== null &&
524
- effect.nodes.end !== null
525
- ) {
526
- remove_effect_dom(effect.nodes.start, /** @type {TemplateNode} */ (effect.nodes.end));
527
- removed = true;
528
- }
522
+ var previous_renderer = custom_renderers_flag ? push_renderer(effect.r) : null;
529
523
 
530
- effect.f |= DESTROYING;
531
- destroy_effect_children(effect, remove_dom && !removed);
532
- remove_reactions(effect, 0);
524
+ try {
525
+ if (
526
+ (remove_dom || (effect.f & HEAD_EFFECT) !== 0) &&
527
+ effect.nodes !== null &&
528
+ effect.nodes.end !== null
529
+ ) {
530
+ remove_effect_dom(effect.nodes.start, /** @type {TemplateNode} */ (effect.nodes.end));
531
+ removed = true;
532
+ }
533
+
534
+ effect.f |= DESTROYING;
535
+ destroy_effect_children(effect, remove_dom && !removed);
536
+ remove_reactions(effect);
533
537
 
534
- var transitions = effect.nodes && effect.nodes.t;
538
+ var transitions = effect.nodes && effect.nodes.t;
535
539
 
536
- if (transitions !== null) {
537
- for (const transition of transitions) {
538
- transition.stop();
540
+ if (transitions !== null) {
541
+ for (const transition of transitions) {
542
+ transition.stop();
543
+ }
539
544
  }
540
- }
541
545
 
542
- execute_effect_teardown(effect);
546
+ execute_effect_teardown(effect);
547
+ } finally {
548
+ // nothing below interacts with the renderer
549
+ if (custom_renderers_flag) pop_renderer(previous_renderer);
550
+ }
543
551
 
544
552
  effect.f ^= DESTROYING;
545
553
  effect.f |= DESTROYED;
@@ -562,10 +570,13 @@ export function destroy_effect(effect, remove_dom = true) {
562
570
  effect.teardown =
563
571
  effect.ctx =
564
572
  effect.deps =
573
+ effect.dv =
574
+ effect.edges =
565
575
  effect.fn =
566
576
  effect.nodes =
567
577
  effect.ac =
568
578
  effect.b =
579
+ effect.r =
569
580
  null;
570
581
  }
571
582
 
@@ -579,7 +590,7 @@ export function remove_effect_dom(node, end) {
579
590
  /** @type {TemplateNode | null} */
580
591
  var next = node === end ? null : get_next_sibling(node);
581
592
 
582
- node.remove();
593
+ remove_node(/** @type {ChildNode} */ (node));
583
594
  node = next;
584
595
  }
585
596
  }
@@ -626,8 +637,28 @@ export function pause_effect(effect, callback, destroy = true) {
626
637
  };
627
638
 
628
639
  var remaining = transitions.length;
640
+
629
641
  if (remaining > 0) {
630
- var check = () => --remaining || fn();
642
+ var context = teardown_context;
643
+
644
+ var check = () => {
645
+ if (!--remaining) {
646
+ var previous_context = teardown_context;
647
+
648
+ try {
649
+ if (context) {
650
+ // Other outros can share this context, and state may have changed
651
+ // since its derived values were cached.
652
+ context.derived_cache.clear();
653
+ set_teardown_context(context);
654
+ }
655
+ fn();
656
+ } finally {
657
+ if (context) set_teardown_context(previous_context);
658
+ }
659
+ }
660
+ };
661
+
631
662
  for (var transition of transitions) {
632
663
  transition.out(check);
633
664
  }
@@ -701,13 +732,13 @@ function resume_children(effect, local) {
701
732
  if ((effect.f & INERT) === 0) return;
702
733
  effect.f ^= INERT;
703
734
 
704
- // If a dependency of this effect changed while it was paused,
735
+ // If a dependency of this effect may have changed while it was paused,
705
736
  // schedule the effect to update. we don't use `is_dirty`
706
737
  // here because we don't want to eagerly recompute a derived like
707
- // `{#if foo}{foo.bar()}{/if}` if `foo` is now `undefined
738
+ // `{#if foo}{foo.bar()}{/if}` if `foo` is now `undefined`.
708
739
  if ((effect.f & CLEAN) === 0) {
709
- set_signal_status(effect, DIRTY);
710
- Batch.ensure().schedule(effect); // Assumption: This happens during the commit phase of the batch, causing another flush, but it's safe
740
+ // Assumption: This happens during the commit phase of the batch, causing another flush, but it's safe
741
+ Batch.ensure().schedule(effect, MAYBE_DIRTY);
711
742
  }
712
743
 
713
744
  var child = effect.first;
@@ -733,10 +764,6 @@ function resume_children(effect, local) {
733
764
  }
734
765
  }
735
766
 
736
- export function aborted(effect = /** @type {Effect} */ (active_effect)) {
737
- return (effect.f & DESTROYED) !== 0;
738
- }
739
-
740
767
  /**
741
768
  * @param {Effect} effect
742
769
  * @param {DocumentFragment} fragment
@@ -744,15 +771,21 @@ export function aborted(effect = /** @type {Effect} */ (active_effect)) {
744
771
  export function move_effect(effect, fragment) {
745
772
  if (!effect.nodes) return;
746
773
 
747
- /** @type {TemplateNode | null} */
748
- var node = effect.nodes.start;
749
- var end = effect.nodes.end;
774
+ var previous_renderer = custom_renderers_flag ? push_renderer(effect.r) : null;
750
775
 
751
- while (node !== null) {
776
+ try {
752
777
  /** @type {TemplateNode | null} */
753
- var next = node === end ? null : get_next_sibling(node);
778
+ var node = effect.nodes.start;
779
+ var end = effect.nodes.end;
754
780
 
755
- fragment.append(node);
756
- node = next;
781
+ while (node !== null) {
782
+ /** @type {TemplateNode | null} */
783
+ var next = node === end ? null : get_next_sibling(node);
784
+
785
+ append_child(fragment, node);
786
+ node = next;
787
+ }
788
+ } finally {
789
+ if (custom_renderers_flag) pop_renderer(previous_renderer);
757
790
  }
758
791
  }
@@ -7,13 +7,12 @@ import {
7
7
  get,
8
8
  set_untracked_writes,
9
9
  untrack,
10
- increment_write_version,
11
10
  update_effect,
12
11
  current_sources,
13
12
  is_dirty,
14
13
  untracking,
15
- is_destroying_effect,
16
- push_reaction_value
14
+ push_reaction_value,
15
+ is_destroying_effect
17
16
  } from '../runtime.js';
18
17
  import { equals, safe_equals } from './equality.js';
19
18
  import {
@@ -25,7 +24,9 @@ import {
25
24
  MAYBE_DIRTY,
26
25
  BLOCK_EFFECT,
27
26
  ROOT_EFFECT,
28
- ASYNC
27
+ ASYNC,
28
+ ASSIGNED,
29
+ ERROR_VALUE
29
30
  } from '#client/constants';
30
31
  import * as e from '../errors.js';
31
32
  import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
@@ -35,21 +36,18 @@ import { component_context, is_runes } from '../context.js';
35
36
  import {
36
37
  Batch,
37
38
  batch_values,
38
- eager_block_effects,
39
- schedule_effect,
40
39
  legacy_updates,
40
+ in_real_world,
41
+ teardown_write,
41
42
  source_stacks
42
43
  } from './batch.js';
43
44
  import { proxy } from '../proxy.js';
44
45
  import { execute_derived } from './deriveds.js';
45
- import { set_signal_status, update_derived_status } from './status.js';
46
+ import { set_signal_status } from './status.js';
46
47
 
47
48
  /** @type {Set<Effect>} */
48
49
  export let eager_effects = new Set();
49
50
 
50
- /** @type {Map<Value, any>} */
51
- export const old_values = new Map();
52
-
53
51
  /**
54
52
  * @param {Set<any>} v
55
53
  */
@@ -57,7 +55,7 @@ export function set_eager_effects(v) {
57
55
  eager_effects = v;
58
56
  }
59
57
 
60
- let eager_effects_deferred = false;
58
+ export let eager_effects_deferred = false;
61
59
 
62
60
  export function set_eager_effects_deferred() {
63
61
  eager_effects_deferred = true;
@@ -169,17 +167,6 @@ export function set(source, value, should_proxy = false) {
169
167
  return internal_set(source, new_value, legacy_updates);
170
168
  }
171
169
 
172
- /**
173
- * A set of signals we have already seen while traversing in mark_reactions.
174
- * Not always set to balance the common case of sources only having a couple
175
- * of (transitive) dependencies (where always creating a Set would be bad for perf)
176
- * with the edge case of extremely deep or wide dependency arrays with cycles.
177
- * @type {Set<any> | null}
178
- */
179
- var seen = null;
180
- /** Number of transitive dependencies, see {@link seen} for more info */
181
- var count_deps = 0;
182
-
183
170
  /**
184
171
  * @template V
185
172
  * @param {Value<V>} source
@@ -188,17 +175,21 @@ var count_deps = 0;
188
175
  * @returns {V}
189
176
  */
190
177
  export function internal_set(source, value, updated_during_traversal = null) {
191
- if (!source.equals(value)) {
192
- if (is_destroying_effect) {
193
- old_values.set(source, value);
194
- } else if (!old_values.has(source)) {
195
- // only record the value from before the first write in this flush, otherwise a
196
- // teardown would see the value from before whichever write happened to be last
197
- old_values.set(source, source.v);
198
- }
178
+ var same = source.equals(value) && (source.f & ERROR_VALUE) === 0;
179
+ var entry = batch_values?.get(source);
199
180
 
181
+ // A value that equals the real one may still overwrite a different value in the active view.
182
+ if (!same || (entry !== undefined && (entry.e || !source.equals.call(entry, value)))) {
200
183
  var batch = Batch.ensure();
201
- batch.capture(source, value);
184
+
185
+ // If we are assigning to a dirty derived we eagerly execute it to track the dependencies. (Not if
186
+ // it's assigned already: it tracks them, and its flags don't tell whether the assignment still holds,
187
+ // which is what other views see when they undo this one — see `is_dirty`)
188
+ if ((source.f & (DERIVED | DIRTY | ASSIGNED)) === (DERIVED | DIRTY)) {
189
+ execute_derived(/** @type {Derived} */ (source));
190
+ }
191
+
192
+ batch.capture(source, value, same, false, updated_during_traversal);
202
193
 
203
194
  if (DEV) {
204
195
  if (tracing_mode_flag || active_effect !== null) {
@@ -231,30 +222,6 @@ export function internal_set(source, value, updated_during_traversal = null) {
231
222
  }
232
223
  }
233
224
 
234
- if ((source.f & DERIVED) !== 0) {
235
- const derived = /** @type {Derived} */ (source);
236
-
237
- // if we are assigning to a dirty derived we set it to clean/maybe dirty but we also eagerly execute it to track the dependencies
238
- if ((source.f & DIRTY) !== 0) {
239
- execute_derived(derived);
240
- }
241
-
242
- // During time traveling we don't want to reset the status so that
243
- // traversal of the graph in the other batches still happens
244
- if (batch_values === null) {
245
- update_derived_status(derived);
246
- }
247
- }
248
-
249
- source.wv = increment_write_version();
250
-
251
- // For debugging, in case you want to know which reactions are being scheduled:
252
- // log_reactions(source);
253
- seen = null;
254
- count_deps = 0;
255
- mark_reactions(source, DIRTY, updated_during_traversal);
256
- seen = null;
257
-
258
225
  // It's possible that the current reaction might not have up-to-date dependencies
259
226
  // whilst it's actively running. So in the case of ensuring it registers the reaction
260
227
  // properly for itself, we need to ensure the current effect actually gets
@@ -271,10 +238,9 @@ export function internal_set(source, value, updated_during_traversal = null) {
271
238
  untracked_writes.push(source);
272
239
  }
273
240
  }
274
-
275
- if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
276
- flush_eager_effects();
277
- }
241
+ } else if (is_destroying_effect) {
242
+ // not a change, but the teardown no longer sees a reverted value
243
+ teardown_write(source);
278
244
  }
279
245
 
280
246
  return value;
@@ -283,6 +249,11 @@ export function internal_set(source, value, updated_during_traversal = null) {
283
249
  export function flush_eager_effects() {
284
250
  eager_effects_deferred = false;
285
251
 
252
+ // eager effects run in the real world, not in the view of a batch
253
+ in_real_world(run_eager_effects);
254
+ }
255
+
256
+ function run_eager_effects() {
286
257
  for (const effect of eager_effects) {
287
258
  // Mark clean inspect-effects as maybe dirty and then check their dirtiness
288
259
  // instead of just updating the effects - this way we avoid overfiring.
@@ -346,68 +317,3 @@ export function update_pre(source, d = 1) {
346
317
  export function increment(source) {
347
318
  set(source, source.v + 1);
348
319
  }
349
-
350
- /**
351
- * @param {Value} signal
352
- * @param {number} status should be DIRTY or MAYBE_DIRTY
353
- * @param {Effect[] | null} updated_during_traversal
354
- * @returns {void}
355
- */
356
- function mark_reactions(signal, status, updated_during_traversal) {
357
- var reactions = signal.reactions;
358
- if (reactions === null) return;
359
-
360
- var runes = is_runes();
361
- var length = reactions.length;
362
-
363
- count_deps += length;
364
- // Activate the `seen` Set if we think from the unusually high number of deps that
365
- // there might be cycles in the graph, to avoid repeated lookups for reactions
366
- // Example: https://github.com/sveltejs/svelte/issues/16658 has a graph with one source
367
- // reaching ~10000 distinct deriveds/effects each, resulting in 65 million walks through repeated visits.
368
- if (count_deps > 100000 && seen === null) seen = new Set();
369
-
370
- if (seen !== null) {
371
- if (seen.has(signal)) return;
372
- seen.add(signal);
373
- }
374
-
375
- for (var i = 0; i < length; i++) {
376
- var reaction = reactions[i];
377
- var flags = reaction.f;
378
-
379
- // In legacy mode, skip the current effect to prevent infinite loops
380
- if (!runes && reaction === active_effect) continue;
381
-
382
- var not_dirty = (flags & DIRTY) === 0;
383
-
384
- // don't set a DIRTY reaction to MAYBE_DIRTY
385
- if (not_dirty) {
386
- set_signal_status(reaction, status);
387
- }
388
-
389
- if ((flags & EAGER_EFFECT) !== 0) {
390
- // Eager effects need to run immediately:
391
- // - for $inspect so that the stack trace makes sense
392
- // - for $state.eager because they might be without an effect parent
393
- eager_effects.add(/** @type {Effect} */ (reaction));
394
- } else if ((flags & DERIVED) !== 0) {
395
- var derived = /** @type {Derived} */ (reaction);
396
-
397
- batch_values?.delete(derived);
398
- mark_reactions(derived, MAYBE_DIRTY, updated_during_traversal);
399
- } else if (not_dirty) {
400
- var effect = /** @type {Effect} */ (reaction);
401
-
402
- if ((flags & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
403
- eager_block_effects.add(effect);
404
- }
405
-
406
- if (updated_during_traversal !== null) {
407
- updated_during_traversal.push(effect);
408
- } else {
409
- schedule_effect(effect);
410
- }
411
- }
412
- }
413
- }
@@ -17,7 +17,7 @@ export function set_signal_status(signal, status) {
17
17
  */
18
18
  export function update_derived_status(derived) {
19
19
  // Only mark as MAYBE_DIRTY if disconnected and has dependencies.
20
- if ((derived.f & CONNECTED) !== 0 || derived.deps === null) {
20
+ if ((derived.f & CONNECTED) !== 0 || derived.edges === null) {
21
21
  set_signal_status(derived, CLEAN);
22
22
  } else {
23
23
  set_signal_status(derived, MAYBE_DIRTY);