svelte 5.57.3 → 5.58.1

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 (81) hide show
  1. package/README.md +1 -1
  2. package/compiler/index.js +1 -1
  3. package/elements.d.ts +1 -2
  4. package/package.json +2 -2
  5. package/src/compiler/phases/1-parse/acorn.js +4 -14
  6. package/src/compiler/phases/1-parse/index.js +8 -1
  7. package/src/compiler/phases/1-parse/read/context.js +3 -2
  8. package/src/compiler/phases/1-parse/read/expression.js +2 -4
  9. package/src/compiler/phases/1-parse/utils/bracket.js +6 -0
  10. package/src/compiler/phases/2-analyze/css/css-prune.js +0 -8
  11. package/src/compiler/phases/2-analyze/index.js +2 -1
  12. package/src/compiler/phases/2-analyze/visitors/AwaitExpression.js +17 -15
  13. package/src/compiler/phases/3-transform/client/transform-template/index.js +27 -9
  14. package/src/compiler/phases/3-transform/client/utils.js +3 -2
  15. package/src/compiler/phases/3-transform/client/visitors/EachBlock.js +1 -1
  16. package/src/compiler/phases/3-transform/client/visitors/Fragment.js +13 -1
  17. package/src/compiler/phases/3-transform/client/visitors/HtmlTag.js +10 -2
  18. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +11 -2
  19. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +15 -7
  20. package/src/compiler/phases/3-transform/client/visitors/SlotElement.js +19 -1
  21. package/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +0 -1
  22. package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +1 -1
  23. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +1 -1
  24. package/src/compiler/phases/3-transform/client/visitors/shared/events.js +1 -1
  25. package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +1 -1
  26. package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +8 -0
  27. package/src/compiler/phases/3-transform/server/visitors/Fragment.js +6 -1
  28. package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +1 -1
  29. package/src/compiler/phases/3-transform/server/visitors/shared/element.js +2 -1
  30. package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +1 -1
  31. package/src/compiler/phases/patterns.js +0 -1
  32. package/src/compiler/print/index.js +49 -73
  33. package/src/compiler/state.js +1 -1
  34. package/src/compiler/utils/builders.js +0 -1
  35. package/src/compiler/utils/mapped_code.js +1 -12
  36. package/src/constants.js +0 -8
  37. package/src/index-client.js +3 -3
  38. package/src/internal/client/constants.js +8 -1
  39. package/src/internal/client/dev/debug.js +6 -6
  40. package/src/internal/client/dev/elements.js +25 -9
  41. package/src/internal/client/dev/tracing.js +67 -11
  42. package/src/internal/client/dom/blocks/async.js +2 -1
  43. package/src/internal/client/dom/blocks/await.js +109 -20
  44. package/src/internal/client/dom/blocks/boundary.js +107 -70
  45. package/src/internal/client/dom/blocks/branches.js +17 -23
  46. package/src/internal/client/dom/blocks/each.js +88 -13
  47. package/src/internal/client/dom/blocks/html.js +44 -10
  48. package/src/internal/client/dom/blocks/slot.js +19 -1
  49. package/src/internal/client/dom/blocks/snippet.js +13 -0
  50. package/src/internal/client/dom/blocks/svelte-component.js +1 -1
  51. package/src/internal/client/dom/blocks/svelte-element.js +2 -1
  52. package/src/internal/client/dom/elements/attributes.js +4 -3
  53. package/src/internal/client/dom/elements/bindings/input.js +19 -10
  54. package/src/internal/client/dom/elements/bindings/select.js +3 -7
  55. package/src/internal/client/dom/elements/events.js +27 -2
  56. package/src/internal/client/dom/hydration.js +4 -1
  57. package/src/internal/client/dom/operations.js +2 -3
  58. package/src/internal/client/dom/template.js +0 -1
  59. package/src/internal/client/error-handling.js +4 -12
  60. package/src/internal/client/errors.js +18 -2
  61. package/src/internal/client/index.js +0 -1
  62. package/src/internal/client/reactivity/async.js +249 -123
  63. package/src/internal/client/reactivity/batch.js +1109 -538
  64. package/src/internal/client/reactivity/deriveds.js +281 -177
  65. package/src/internal/client/reactivity/effects.js +44 -28
  66. package/src/internal/client/reactivity/equality.js +0 -9
  67. package/src/internal/client/reactivity/props.js +0 -1
  68. package/src/internal/client/reactivity/sources.js +33 -125
  69. package/src/internal/client/reactivity/status.js +1 -1
  70. package/src/internal/client/render.js +11 -0
  71. package/src/internal/client/runtime.js +925 -152
  72. package/src/internal/client/validate.js +2 -2
  73. package/src/internal/server/renderer.js +52 -118
  74. package/src/internal/shared/utils.js +12 -0
  75. package/src/motion/spring.js +1 -1
  76. package/src/motion/tweened.js +1 -1
  77. package/src/reactivity/create-subscriber.js +1 -1
  78. package/src/version.js +1 -1
  79. package/types/index.d.ts +3 -3
  80. package/types/index.d.ts.map +1 -1
  81. 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,
@@ -43,9 +45,8 @@ import { DEV } from 'esm-env';
43
45
  import { define_property } from '../../shared/utils.js';
44
46
  import { get_next_sibling } 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';
50
51
 
51
52
  /**
@@ -103,6 +104,8 @@ function create_effect(type, fn) {
103
104
  var effect = {
104
105
  ctx: component_context,
105
106
  deps: null,
107
+ dv: null,
108
+ edges: null,
106
109
  nodes: null,
107
110
  f: type | DIRTY | CONNECTED,
108
111
  first: null,
@@ -121,8 +124,6 @@ function create_effect(type, fn) {
121
124
  effect.component_function = dev_current_component_function;
122
125
  }
123
126
 
124
- current_batch?.register_created_effect(effect);
125
-
126
127
  /** @type {Effect | null} */
127
128
  var e = effect;
128
129
 
@@ -132,7 +133,7 @@ function create_effect(type, fn) {
132
133
  collected_effects.push(effect);
133
134
  } else {
134
135
  // schedule for later
135
- Batch.ensure().schedule(effect);
136
+ Batch.ensure().schedule(effect, DIRTY);
136
137
  }
137
138
  } else if (fn !== null) {
138
139
  try {
@@ -146,7 +147,7 @@ function create_effect(type, fn) {
146
147
  // won't re-run, has no DOM, and has no teardown etc)
147
148
  // then we skip it and go to its child (if any)
148
149
  if (
149
- e.deps === null &&
150
+ e.edges === null &&
150
151
  e.teardown === null &&
151
152
  e.nodes === null &&
152
153
  e.first === e.last && // either `null`, or a singular child
@@ -352,7 +353,7 @@ export function legacy_pre_effect_reset() {
352
353
 
353
354
  // If the effect is CLEAN, then make it MAYBE_DIRTY. This ensures we traverse through
354
355
  // the effects dependencies and correctly ensure each dependency is up-to-date.
355
- if ((effect.f & CLEAN) !== 0 && effect.deps !== null) {
356
+ if ((effect.f & CLEAN) !== 0 && effect.edges !== null) {
356
357
  set_signal_status(effect, MAYBE_DIRTY);
357
358
  }
358
359
 
@@ -446,6 +447,8 @@ export function execute_effect_teardown(effect) {
446
447
  var teardown = effect.teardown;
447
448
  if (teardown !== null) {
448
449
  const previously_destroying_effect = is_destroying_effect;
450
+ const previous_teardown_version = teardown_version;
451
+ const previous_teardown_context = teardown_context;
449
452
  const previous_reaction = active_reaction;
450
453
  set_is_destroying_effect(true);
451
454
  set_active_reaction(null);
@@ -457,7 +460,8 @@ export function execute_effect_teardown(effect) {
457
460
  // themselves mid-teardown are skipped by invoke_error_boundary.
458
461
  invoke_error_boundary(error, effect.parent);
459
462
  } finally {
460
- set_is_destroying_effect(previously_destroying_effect);
463
+ set_is_destroying_effect(previously_destroying_effect, previous_teardown_version);
464
+ set_teardown_context(previous_teardown_context);
461
465
  set_active_reaction(previous_reaction);
462
466
  }
463
467
  }
@@ -473,13 +477,7 @@ export function destroy_effect_children(signal, remove_dom = false) {
473
477
  signal.first = signal.last = null;
474
478
 
475
479
  while (effect !== null) {
476
- const controller = effect.ac;
477
-
478
- if (controller !== null) {
479
- without_reactive_context(() => {
480
- controller.abort(STALE_REACTION);
481
- });
482
- }
480
+ abort_all(effect);
483
481
 
484
482
  var next = effect.next;
485
483
 
@@ -529,7 +527,7 @@ export function destroy_effect(effect, remove_dom = true) {
529
527
 
530
528
  effect.f |= DESTROYING;
531
529
  destroy_effect_children(effect, remove_dom && !removed);
532
- remove_reactions(effect, 0);
530
+ remove_reactions(effect);
533
531
 
534
532
  var transitions = effect.nodes && effect.nodes.t;
535
533
 
@@ -562,6 +560,8 @@ export function destroy_effect(effect, remove_dom = true) {
562
560
  effect.teardown =
563
561
  effect.ctx =
564
562
  effect.deps =
563
+ effect.dv =
564
+ effect.edges =
565
565
  effect.fn =
566
566
  effect.nodes =
567
567
  effect.ac =
@@ -626,8 +626,28 @@ export function pause_effect(effect, callback, destroy = true) {
626
626
  };
627
627
 
628
628
  var remaining = transitions.length;
629
+
629
630
  if (remaining > 0) {
630
- var check = () => --remaining || fn();
631
+ var context = teardown_context;
632
+
633
+ var check = () => {
634
+ if (!--remaining) {
635
+ var previous_context = teardown_context;
636
+
637
+ try {
638
+ if (context) {
639
+ // Other outros can share this context, and state may have changed
640
+ // since its derived values were cached.
641
+ context.derived_cache.clear();
642
+ set_teardown_context(context);
643
+ }
644
+ fn();
645
+ } finally {
646
+ if (context) set_teardown_context(previous_context);
647
+ }
648
+ }
649
+ };
650
+
631
651
  for (var transition of transitions) {
632
652
  transition.out(check);
633
653
  }
@@ -701,13 +721,13 @@ function resume_children(effect, local) {
701
721
  if ((effect.f & INERT) === 0) return;
702
722
  effect.f ^= INERT;
703
723
 
704
- // If a dependency of this effect changed while it was paused,
724
+ // If a dependency of this effect may have changed while it was paused,
705
725
  // schedule the effect to update. we don't use `is_dirty`
706
726
  // here because we don't want to eagerly recompute a derived like
707
- // `{#if foo}{foo.bar()}{/if}` if `foo` is now `undefined
727
+ // `{#if foo}{foo.bar()}{/if}` if `foo` is now `undefined`.
708
728
  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
729
+ // Assumption: This happens during the commit phase of the batch, causing another flush, but it's safe
730
+ Batch.ensure().schedule(effect, MAYBE_DIRTY);
711
731
  }
712
732
 
713
733
  var child = effect.first;
@@ -733,10 +753,6 @@ function resume_children(effect, local) {
733
753
  }
734
754
  }
735
755
 
736
- export function aborted(effect = /** @type {Effect} */ (active_effect)) {
737
- return (effect.f & DESTROYED) !== 0;
738
- }
739
-
740
756
  /**
741
757
  * @param {Effect} effect
742
758
  * @param {DocumentFragment} fragment
@@ -16,15 +16,6 @@ export function safe_not_equal(a, b) {
16
16
  : a !== b || (a !== null && typeof a === 'object') || typeof a === 'function';
17
17
  }
18
18
 
19
- /**
20
- * @param {unknown} a
21
- * @param {unknown} b
22
- * @returns {boolean}
23
- */
24
- export function not_equal(a, b) {
25
- return a !== b;
26
- }
27
-
28
19
  /** @type {Equals} */
29
20
  export function safe_equals(value) {
30
21
  return !safe_not_equal(value, this.v);
@@ -22,7 +22,6 @@ import { DESTROYED, LEGACY_PROPS, STATE_SYMBOL } from '#client/constants';
22
22
  import { proxy } from '../proxy.js';
23
23
  import { capture_store_binding } from './store.js';
24
24
  import { legacy_mode_flag } from '../../flags/index.js';
25
- import { effect, render_effect } from './effects.js';
26
25
 
27
26
  /**
28
27
  * @param {((value?: number) => number)} fn
@@ -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,20 +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
- legacy_updates
39
+ legacy_updates,
40
+ in_real_world,
41
+ teardown_write,
42
+ source_stacks
41
43
  } from './batch.js';
42
44
  import { proxy } from '../proxy.js';
43
45
  import { execute_derived } from './deriveds.js';
44
- import { set_signal_status, update_derived_status } from './status.js';
46
+ import { set_signal_status } from './status.js';
45
47
 
46
48
  /** @type {Set<Effect>} */
47
49
  export let eager_effects = new Set();
48
50
 
49
- /** @type {Map<Value, any>} */
50
- export const old_values = new Map();
51
-
52
51
  /**
53
52
  * @param {Set<any>} v
54
53
  */
@@ -56,7 +55,7 @@ export function set_eager_effects(v) {
56
55
  eager_effects = v;
57
56
  }
58
57
 
59
- let eager_effects_deferred = false;
58
+ export let eager_effects_deferred = false;
60
59
 
61
60
  export function set_eager_effects_deferred() {
62
61
  eager_effects_deferred = true;
@@ -168,17 +167,6 @@ export function set(source, value, should_proxy = false) {
168
167
  return internal_set(source, new_value, legacy_updates);
169
168
  }
170
169
 
171
- /**
172
- * A set of signals we have already seen while traversing in mark_reactions.
173
- * Not always set to balance the common case of sources only having a couple
174
- * of (transitive) dependencies (where always creating a Set would be bad for perf)
175
- * with the edge case of extremely deep or wide dependency arrays with cycles.
176
- * @type {Set<any> | null}
177
- */
178
- var seen = null;
179
- /** Number of transitive dependencies, see {@link seen} for more info */
180
- var count_deps = 0;
181
-
182
170
  /**
183
171
  * @template V
184
172
  * @param {Value<V>} source
@@ -187,21 +175,26 @@ var count_deps = 0;
187
175
  * @returns {V}
188
176
  */
189
177
  export function internal_set(source, value, updated_during_traversal = null) {
190
- if (!source.equals(value)) {
191
- if (is_destroying_effect) {
192
- old_values.set(source, value);
193
- } else if (!old_values.has(source)) {
194
- // only record the value from before the first write in this flush, otherwise a
195
- // teardown would see the value from before whichever write happened to be last
196
- old_values.set(source, source.v);
197
- }
178
+ var same = source.equals(value) && (source.f & ERROR_VALUE) === 0;
179
+ var entry = batch_values?.get(source);
198
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)))) {
199
183
  var batch = Batch.ensure();
200
- 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);
201
193
 
202
194
  if (DEV) {
203
195
  if (tracing_mode_flag || active_effect !== null) {
204
196
  source.updated ??= new Map();
197
+ source_stacks.add(source);
205
198
 
206
199
  // For performance reasons, when not using $inspect.trace, we only start collecting stack traces
207
200
  // after the same source has been updated more than 5 times in the same flush cycle.
@@ -229,30 +222,6 @@ export function internal_set(source, value, updated_during_traversal = null) {
229
222
  }
230
223
  }
231
224
 
232
- if ((source.f & DERIVED) !== 0) {
233
- const derived = /** @type {Derived} */ (source);
234
-
235
- // 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
236
- if ((source.f & DIRTY) !== 0) {
237
- execute_derived(derived);
238
- }
239
-
240
- // During time traveling we don't want to reset the status so that
241
- // traversal of the graph in the other batches still happens
242
- if (batch_values === null) {
243
- update_derived_status(derived);
244
- }
245
- }
246
-
247
- source.wv = increment_write_version();
248
-
249
- // For debugging, in case you want to know which reactions are being scheduled:
250
- // log_reactions(source);
251
- seen = null;
252
- count_deps = 0;
253
- mark_reactions(source, DIRTY, updated_during_traversal);
254
- seen = null;
255
-
256
225
  // It's possible that the current reaction might not have up-to-date dependencies
257
226
  // whilst it's actively running. So in the case of ensuring it registers the reaction
258
227
  // properly for itself, we need to ensure the current effect actually gets
@@ -269,10 +238,9 @@ export function internal_set(source, value, updated_during_traversal = null) {
269
238
  untracked_writes.push(source);
270
239
  }
271
240
  }
272
-
273
- if (!batch.is_fork && eager_effects.size > 0 && !eager_effects_deferred) {
274
- flush_eager_effects();
275
- }
241
+ } else if (is_destroying_effect) {
242
+ // not a change, but the teardown no longer sees a reverted value
243
+ teardown_write(source);
276
244
  }
277
245
 
278
246
  return value;
@@ -281,6 +249,11 @@ export function internal_set(source, value, updated_during_traversal = null) {
281
249
  export function flush_eager_effects() {
282
250
  eager_effects_deferred = false;
283
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() {
284
257
  for (const effect of eager_effects) {
285
258
  // Mark clean inspect-effects as maybe dirty and then check their dirtiness
286
259
  // instead of just updating the effects - this way we avoid overfiring.
@@ -344,68 +317,3 @@ export function update_pre(source, d = 1) {
344
317
  export function increment(source) {
345
318
  set(source, source.v + 1);
346
319
  }
347
-
348
- /**
349
- * @param {Value} signal
350
- * @param {number} status should be DIRTY or MAYBE_DIRTY
351
- * @param {Effect[] | null} updated_during_traversal
352
- * @returns {void}
353
- */
354
- function mark_reactions(signal, status, updated_during_traversal) {
355
- var reactions = signal.reactions;
356
- if (reactions === null) return;
357
-
358
- var runes = is_runes();
359
- var length = reactions.length;
360
-
361
- count_deps += length;
362
- // Activate the `seen` Set if we think from the unusually high number of deps that
363
- // there might be cycles in the graph, to avoid repeated lookups for reactions
364
- // Example: https://github.com/sveltejs/svelte/issues/16658 has a graph with one source
365
- // reaching ~10000 distinct deriveds/effects each, resulting in 65 million walks through repeated visits.
366
- if (count_deps > 100000 && seen === null) seen = new Set();
367
-
368
- if (seen !== null) {
369
- if (seen.has(signal)) return;
370
- seen.add(signal);
371
- }
372
-
373
- for (var i = 0; i < length; i++) {
374
- var reaction = reactions[i];
375
- var flags = reaction.f;
376
-
377
- // In legacy mode, skip the current effect to prevent infinite loops
378
- if (!runes && reaction === active_effect) continue;
379
-
380
- var not_dirty = (flags & DIRTY) === 0;
381
-
382
- // don't set a DIRTY reaction to MAYBE_DIRTY
383
- if (not_dirty) {
384
- set_signal_status(reaction, status);
385
- }
386
-
387
- if ((flags & EAGER_EFFECT) !== 0) {
388
- // Eager effects need to run immediately:
389
- // - for $inspect so that the stack trace makes sense
390
- // - for $state.eager because they might be without an effect parent
391
- eager_effects.add(/** @type {Effect} */ (reaction));
392
- } else if ((flags & DERIVED) !== 0) {
393
- var derived = /** @type {Derived} */ (reaction);
394
-
395
- batch_values?.delete(derived);
396
- mark_reactions(derived, MAYBE_DIRTY, updated_during_traversal);
397
- } else if (not_dirty) {
398
- var effect = /** @type {Effect} */ (reaction);
399
-
400
- if ((flags & BLOCK_EFFECT) !== 0 && eager_block_effects !== null) {
401
- eager_block_effects.add(effect);
402
- }
403
-
404
- if (updated_during_traversal !== null) {
405
- updated_during_traversal.push(effect);
406
- } else {
407
- schedule_effect(effect);
408
- }
409
- }
410
- }
411
- }
@@ -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);
@@ -25,6 +25,8 @@ import { assign_nodes } from './dom/template.js';
25
25
  import { is_passive_event } from '../../utils.js';
26
26
  import { COMMENT_NODE, TEXT_CACHE } from './constants.js';
27
27
  import { boundary } from './dom/blocks/boundary.js';
28
+ import { current_batch } from './reactivity/batch.js';
29
+ import { async_mode_flag } from '../flags/index.js';
28
30
 
29
31
  /**
30
32
  * This is normally true — block effects should run their intro transitions —
@@ -118,6 +120,15 @@ export function hydrate(component, options) {
118
120
 
119
121
  const instance = _mount(component, { ...options, anchor });
120
122
 
123
+ // The server rendered the hydrated DOM with the state that hydration ran with (set before `hydrate()`,
124
+ // or while hydrating, e.g. by lazily initialized state), so that state is the real world from now on.
125
+ // This is what happens when mounting, too, where the batch commits right away because the root boundary
126
+ // is pending. Otherwise, while the hydration batch waits for async work, other batches' views would undo
127
+ // those writes — e.g. that of a pending boundary's content, which renders in a batch of its own
128
+ if (async_mode_flag && current_batch !== null) {
129
+ current_batch.commit_writes();
130
+ }
131
+
121
132
  set_hydrating(false);
122
133
 
123
134
  return /** @type {Exports} */ (instance);