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
@@ -133,23 +133,26 @@ function pause_effects(state, to_destroy, controlled_anchor) {
133
133
 
134
134
  /**
135
135
  * @param {EachState} state
136
- * @param {Effect[]} to_destroy
137
- * @param {boolean} remove_dom
136
+ * @returns {Set<Effect>}
138
137
  */
139
- function destroy_effects(state, to_destroy, remove_dom = true) {
140
- /** @type {Set<Effect> | undefined} */
141
- var preserved_effects;
142
-
138
+ function selected_effects(state) {
139
+ var selected = new Set();
143
140
  // The loop-in-a-loop isn't ideal, but we should only hit this in relatively rare cases
144
- if (state.pending.size > 0) {
145
- preserved_effects = new Set();
146
-
147
- for (const keys of state.pending.values()) {
148
- for (const key of keys) {
149
- preserved_effects.add(/** @type {EachItem} */ (state.items.get(key)).e);
150
- }
141
+ for (const keys of state.pending.values()) {
142
+ for (const key of keys) {
143
+ selected.add(/** @type {EachItem} */ (state.items.get(key)).e);
151
144
  }
152
145
  }
146
+ return selected;
147
+ }
148
+
149
+ /**
150
+ * @param {EachState} state
151
+ * @param {Effect[]} to_destroy
152
+ * @param {boolean} remove_dom
153
+ */
154
+ function destroy_effects(state, to_destroy, remove_dom = true) {
155
+ var preserved_effects = state.pending.size > 0 ? selected_effects(state) : undefined;
153
156
 
154
157
  for (var i = 0; i < to_destroy.length; i++) {
155
158
  var e = to_destroy[i];
@@ -159,12 +162,34 @@ function destroy_effects(state, to_destroy, remove_dom = true) {
159
162
 
160
163
  const fragment = document.createDocumentFragment();
161
164
  move_effect(e, fragment);
165
+
166
+ // `reconcile` expects offscreen items to come after all onscreen items
167
+ if (e !== state.effect.last) {
168
+ link(state, e.prev, e.next);
169
+ link(state, state.effect.last, e);
170
+ link(state, e, null);
171
+ }
162
172
  } else {
163
173
  destroy_effect(to_destroy[i], remove_dom);
164
174
  }
165
175
  }
166
176
  }
167
177
 
178
+ /**
179
+ * Whether the item is outroing, i.e. `pause_effects` destroys it (or keeps it offscreen) once its outro is done
180
+ * @param {EachState} state
181
+ * @param {Effect} effect
182
+ */
183
+ function is_outroing(state, effect) {
184
+ if (state.outrogroups !== null) {
185
+ for (const group of state.outrogroups) {
186
+ if (group.pending.has(effect) || group.done.has(effect)) return true;
187
+ }
188
+ }
189
+
190
+ return false;
191
+ }
192
+
168
193
  /** @type {TemplateNode} */
169
194
  var offscreen_anchor;
170
195
 
@@ -256,6 +281,8 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
256
281
  });
257
282
  }
258
283
  }
284
+
285
+ destroy_unselected();
259
286
  }
260
287
 
261
288
  /**
@@ -263,6 +290,42 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
263
290
  */
264
291
  function discard(batch) {
265
292
  state.pending.delete(batch);
293
+
294
+ if ((state.effect.f & DESTROYED) === 0) {
295
+ destroy_unselected();
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Destroys the offscreen items that no pending batch selects anymore. Offscreen items only exist
301
+ * for the batches that select them: they were created in their view, or kept for them when a
302
+ * commit removed them (see `destroy_effects`). A batch stops selecting an item when it's discarded,
303
+ * or when its block runs again without it. `reconcile` doesn't destroy such an item if it was kept,
304
+ * as kept items are paused, and it leaves paused items alone (taking them to be outroing)
305
+ */
306
+ function destroy_unselected() {
307
+ /** @type {Set<Effect> | undefined} */
308
+ var selected;
309
+ var effect = state.effect.last;
310
+
311
+ // offscreen items come after all onscreen items (see `destroy_effects`)
312
+ while (effect !== null) {
313
+ var prev = effect.prev;
314
+
315
+ // (an offscreen fallback isn't paused, so the next commit shows it or destroys it, see above)
316
+ if ((effect.f & BRANCH_EFFECT) !== 0 && effect !== fallback) {
317
+ if ((effect.f & EFFECT_OFFSCREEN) === 0) break;
318
+
319
+ // create lazily to save work in the common case
320
+ selected ??= selected_effects(state);
321
+
322
+ if (!selected.has(effect) && !is_outroing(state, effect)) {
323
+ destroy_effect(effect);
324
+ }
325
+ }
326
+
327
+ effect = prev;
328
+ }
266
329
  }
267
330
 
268
331
  var effect = block(() => {
@@ -336,7 +399,9 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
336
399
  );
337
400
 
338
401
  if (!first_run) {
402
+ // until it is committed, the item only exists for the batches that select it
339
403
  item.e.f |= EFFECT_OFFSCREEN;
404
+ if (defer) batch.unskip_new_effect(item.e);
340
405
  }
341
406
 
342
407
  items.set(key, item);
@@ -350,7 +415,17 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
350
415
  fallback = branch(() => fallback_fn(anchor));
351
416
  } else {
352
417
  fallback = branch(() => fallback_fn((offscreen_anchor ??= create_text())));
418
+ // until it is committed, the fallback only exists for the batches that select it
353
419
  fallback.f |= EFFECT_OFFSCREEN;
420
+ if (defer) batch.unskip_new_effect(fallback);
421
+ }
422
+ }
423
+
424
+ if (defer && fallback !== null) {
425
+ if (length === 0) {
426
+ batch.unskip_effect(fallback);
427
+ } else {
428
+ batch.skip_effect(fallback);
354
429
  }
355
430
  }
356
431
 
@@ -1,4 +1,4 @@
1
- /** @import { Effect, TemplateNode } from '#client' */
1
+ /** @import { DevStackEntry, Effect, TemplateNode } from '#client' */
2
2
  /** @import {} from 'trusted-types' */
3
3
  import {
4
4
  FILENAME,
@@ -13,25 +13,23 @@ import { assign_nodes } from '../template.js';
13
13
  import * as w from '../../warnings.js';
14
14
  import { hash, sanitize_location } from '../../../../utils.js';
15
15
  import { DEV } from 'esm-env';
16
- import { dev_current_component_function } from '../../context.js';
16
+ import { component_context, dev_current_component_function, dev_stack } from '../../context.js';
17
17
  import { create_element, get_first_child, get_next_sibling } from '../operations.js';
18
18
  import { active_effect } from '../../runtime.js';
19
- import { COMMENT_NODE } from '#client/constants';
19
+ import { COMMENT_NODE, ELEMENT_NODE } from '#client/constants';
20
20
 
21
21
  /**
22
- * @param {Element} element
23
22
  * @param {string | null} server_hash
24
23
  * @param {string | TrustedHTML} value
24
+ * @param {[string, number, number] | undefined} loc
25
25
  */
26
- function check_hash(element, server_hash, value) {
26
+ function check_hash(server_hash, value, loc) {
27
27
  if (!server_hash || server_hash === hash(String(value ?? ''))) return;
28
28
 
29
29
  let location;
30
30
 
31
- // @ts-expect-error
32
- const loc = element.__svelte_meta?.loc;
33
31
  if (loc) {
34
- location = `near ${loc.file}:${loc.line}:${loc.column}`;
32
+ location = `near ${loc[0]}:${loc[1]}:${loc[2]}`;
35
33
  } else if (dev_current_component_function?.[FILENAME]) {
36
34
  location = `in ${dev_current_component_function[FILENAME]}`;
37
35
  }
@@ -39,6 +37,34 @@ function check_hash(element, server_hash, value) {
39
37
  w.hydration_html_changed(sanitize_location(location));
40
38
  }
41
39
 
40
+ /**
41
+ * Assigns the location of the `{@html ...}` tag to the top-level elements it created,
42
+ * which also prevents the surrounding template from assigning its locations to them
43
+ * @param {Effect} effect
44
+ * @param {DevStackEntry | null} parent
45
+ * @param {[string, number, number]} loc
46
+ */
47
+ function assign_locations(effect, parent, loc) {
48
+ if (effect.nodes === null) return;
49
+
50
+ /** @type {TemplateNode | null} */
51
+ var node = effect.nodes.start;
52
+
53
+ while (node !== null) {
54
+ if (node.nodeType === ELEMENT_NODE) {
55
+ // @ts-expect-error
56
+ node.__svelte_meta = {
57
+ parent,
58
+ loc: { file: loc[0], line: loc[1], column: loc[2] },
59
+ component: component_context
60
+ };
61
+ }
62
+
63
+ if (node === effect.nodes.end) break;
64
+ node = get_next_sibling(node);
65
+ }
66
+ }
67
+
42
68
  /**
43
69
  * @param {Element | Text | Comment} node
44
70
  * @param {() => string | TrustedHTML} get_value
@@ -46,6 +72,7 @@ function check_hash(element, server_hash, value) {
46
72
  * @param {boolean} [svg]
47
73
  * @param {boolean} [mathml]
48
74
  * @param {boolean} [skip_warning]
75
+ * @param {[string, number, number]} [location] the filename, line and column of the tag
49
76
  * @returns {void}
50
77
  */
51
78
  export function html(
@@ -54,9 +81,11 @@ export function html(
54
81
  is_controlled = false,
55
82
  svg = false,
56
83
  mathml = false,
57
- skip_warning = false
84
+ skip_warning = false,
85
+ location
58
86
  ) {
59
87
  var anchor = node;
88
+ var parent = DEV ? dev_stack : null;
60
89
 
61
90
  /** @type {string | TrustedHTML} */
62
91
  var value = '';
@@ -88,6 +117,8 @@ export function html(
88
117
  /** @type {TemplateNode} */ (get_first_child(parent_node)),
89
118
  /** @type {TemplateNode} */ (parent_node.lastChild)
90
119
  );
120
+
121
+ if (DEV && location) assign_locations(effect, parent, location);
91
122
  }
92
123
 
93
124
  return;
@@ -123,10 +154,11 @@ export function html(
123
154
  }
124
155
 
125
156
  if (DEV && !skip_warning) {
126
- check_hash(/** @type {Element} */ (next.parentNode), hash, value);
157
+ check_hash(hash, value, location);
127
158
  }
128
159
 
129
160
  assign_nodes(hydrate_node, last);
161
+ if (DEV && location) assign_locations(effect, parent, location);
130
162
  anchor = set_hydrate_node(next);
131
163
  return;
132
164
  }
@@ -149,6 +181,8 @@ export function html(
149
181
  /** @type {TemplateNode} */ (node.lastChild)
150
182
  );
151
183
 
184
+ if (DEV && location) assign_locations(effect, parent, location);
185
+
152
186
  if (svg || mathml) {
153
187
  while (get_first_child(node)) {
154
188
  anchor.before(/** @type {TemplateNode} */ (get_first_child(node)));
@@ -1,3 +1,5 @@
1
+ import { DEV } from 'esm-env';
2
+ import { component_context, dev_stack } from '../../context.js';
1
3
  import { hydrate_next, hydrating } from '../hydration.js';
2
4
  import { create_element, create_text } from '../operations.js';
3
5
  import { append } from '../template.js';
@@ -8,8 +10,9 @@ import { append } from '../template.js';
8
10
  * @param {string} name
9
11
  * @param {Record<string, unknown>} slot_props
10
12
  * @param {null | ((anchor: Comment) => void)} fallback_fn
13
+ * @param {[string, number, number]} [location] the filename, line and column of the slot
11
14
  */
12
- export function slot(anchor, $$props, name, slot_props, fallback_fn) {
15
+ export function slot(anchor, $$props, name, slot_props, fallback_fn, location) {
13
16
  if (hydrating) {
14
17
  hydrate_next();
15
18
  }
@@ -20,6 +23,21 @@ export function slot(anchor, $$props, name, slot_props, fallback_fn) {
20
23
  const element = create_element('slot');
21
24
  if (name !== 'default') element.name = name;
22
25
 
26
+ if (DEV && location) {
27
+ // Native slots are created outside the template, so mark their ownership
28
+ // before the surrounding template assigns its locations.
29
+ // @ts-expect-error
30
+ element.__svelte_meta = {
31
+ parent: dev_stack,
32
+ loc: {
33
+ file: location[0],
34
+ line: location[1],
35
+ column: location[2]
36
+ },
37
+ component: component_context
38
+ };
39
+ }
40
+
23
41
  append(anchor, element);
24
42
 
25
43
  if (fallback_fn !== null) {
@@ -4,7 +4,9 @@
4
4
  import { EFFECT_TRANSPARENT, ELEMENT_NODE } from '#client/constants';
5
5
  import { block, teardown } from '../../reactivity/effects.js';
6
6
  import {
7
+ component_context,
7
8
  dev_current_component_function,
9
+ dev_stack,
8
10
  set_dev_current_component_function
9
11
  } from '../../context.js';
10
12
  import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
@@ -93,6 +95,17 @@ export function createRawSnippet(fn) {
93
95
  anchor.before(element);
94
96
  }
95
97
 
98
+ if (DEV && dev_stack !== null) {
99
+ // Raw snippets have no template locations, so use the render callsite.
100
+ // This also keeps the surrounding template from claiming their root.
101
+ // @ts-expect-error
102
+ element.__svelte_meta = {
103
+ parent: dev_stack,
104
+ loc: { file: dev_stack.file, line: dev_stack.line, column: dev_stack.column },
105
+ component: component_context
106
+ };
107
+ }
108
+
96
109
  const result = snippet.setup?.(element);
97
110
  assign_nodes(element, element);
98
111
 
@@ -11,7 +11,7 @@ import {
11
11
  skip_nodes
12
12
  } from '../hydration.js';
13
13
  import { BranchManager } from './branches.js';
14
- import { HYDRATION_START, HYDRATION_START_ELSE } from '../../../../constants.js';
14
+ import { HYDRATION_START } from '../../../../constants.js';
15
15
 
16
16
  /**
17
17
  * @template P
@@ -82,7 +82,8 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
82
82
  file: filename,
83
83
  line: location[0],
84
84
  column: location[1]
85
- }
85
+ },
86
+ component: component_context
86
87
  };
87
88
  }
88
89
 
@@ -1,8 +1,9 @@
1
- /** @import { Blocker, Effect } from '#client' */
1
+ /** @import { Effect } from '#client' */
2
+ /** @import { Blocker } from '../../reactivity/async.js' */
2
3
  import { DEV } from 'esm-env';
3
4
  import { hydrating, set_hydrating } from '../hydration.js';
4
5
  import { get_descriptors, get_prototype_of } from '../../../shared/utils.js';
5
- import { create_event, delegate, delegated, event, event_symbol } from './events.js';
6
+ import { create_event, delegate, delegated } from './events.js';
6
7
  import { add_form_reset_listener, autofocus } from './misc.js';
7
8
  import * as w from '../../warnings.js';
8
9
  import {
@@ -351,7 +352,7 @@ function set_attributes(
351
352
  // the value is set to the text content of the option element, and setting the value
352
353
  // to null or undefined means the value is set to the string "null" or "undefined".
353
354
  // To align with how we handle this case in non-spread-scenarios, this logic is needed.
354
- // There's a super-edge-case bug here that is left in in favor of smaller code size:
355
+ // There's a super-edge-case bug here that is left in favor of smaller code size:
355
356
  // Because of the "set missing props to null" logic above, we can't differentiate
356
357
  // between a missing value and an explicitly set value of null or undefined. That means
357
358
  // that once set, the value attribute of an <option> element can't be removed. This is
@@ -7,8 +7,7 @@ import { is } from '../../../proxy.js';
7
7
  import { queue_micro_task } from '../../task.js';
8
8
  import { hydrating } from '../../hydration.js';
9
9
  import { tick, untrack } from '../../../runtime.js';
10
- import { current_batch, previous_batch } from '../../../reactivity/batch.js';
11
- import { async_mode_flag } from '../../../../flags/index.js';
10
+ import { current_batch, view_batch } from '../../../reactivity/batch.js';
12
11
 
13
12
  /**
14
13
  * @param {HTMLInputElement} input
@@ -87,16 +86,12 @@ export function bind_value(input, get, set = get) {
87
86
  var value = get();
88
87
 
89
88
  if (input === document.activeElement) {
90
- // In sync mode render effects are executed during tree traversal -> needs current_batch
91
- // In async mode render effects are flushed once batch resolved, at which point current_batch is null -> needs previous_batch
92
- var batch = /** @type {Batch} */ (async_mode_flag ? previous_batch : current_batch);
93
-
94
89
  // Never rewrite the contents of a focused input. We can get here if, for example,
95
90
  // an update is deferred because of async work depending on the input:
96
91
  //
97
92
  // <input bind:value={query}>
98
93
  // <p>{await find(query)}</p>
99
- if (batches.has(batch)) {
94
+ if (batches.has(/** @type {Batch} */ (view_batch))) {
100
95
  return;
101
96
  }
102
97
  }
@@ -294,9 +289,23 @@ function to_number(value) {
294
289
  * @param {(value: FileList | null) => void} set
295
290
  */
296
291
  export function bind_files(input, get, set = get) {
297
- listen_to_event_and_reset_event(input, 'change', () => {
298
- set(input.files);
299
- });
292
+ listen_to_event_and_reset_event(
293
+ input,
294
+ 'change',
295
+ () => {
296
+ set(input.files);
297
+ },
298
+ () => {
299
+ // A form reset can empty the input's `FileList` in place, which is then the very
300
+ // object the binding already holds and would not be seen as a change: give the
301
+ // input a new, empty one instead
302
+ if (typeof DataTransfer === 'function') {
303
+ input.files = new DataTransfer().files;
304
+ }
305
+
306
+ set(input.files);
307
+ }
308
+ );
300
309
 
301
310
  if (
302
311
  // If we are hydrating and the value has since changed,
@@ -1,10 +1,10 @@
1
+ /** @import { Batch } from '../../../reactivity/batch.js' */
1
2
  import { effect, teardown } from '../../../reactivity/effects.js';
2
3
  import { listen_to_event_and_reset_event } from './shared.js';
3
4
  import { is } from '../../../proxy.js';
4
5
  import { is_array } from '../../../../shared/utils.js';
5
6
  import * as w from '../../../warnings.js';
6
- import { Batch, current_batch, previous_batch } from '../../../reactivity/batch.js';
7
- import { async_mode_flag } from '../../../../flags/index.js';
7
+ import { current_batch, view_batch } from '../../../reactivity/batch.js';
8
8
 
9
9
  /**
10
10
  * Sets the `selected` attribute on an option so form reset can restore it.
@@ -194,16 +194,12 @@ export function bind_select_value(select, get, set = get) {
194
194
  var value = get();
195
195
 
196
196
  if (select === document.activeElement) {
197
- // In sync mode render effects are executed during tree traversal -> needs current_batch
198
- // In async mode render effects are flushed once batch resolved, at which point current_batch is null -> needs previous_batch
199
- var batch = /** @type {Batch} */ (async_mode_flag ? previous_batch : current_batch);
200
-
201
197
  // Don't update the <select> if it is focused. We can get here if, for example,
202
198
  // an update is deferred because of async work depending on the select:
203
199
  //
204
200
  // <select bind:value={selected}>...</select>
205
201
  // <p>{await find(selected)}</p>
206
- if (batches.has(batch)) {
202
+ if (batches.has(/** @type {Batch} */ (view_batch))) {
207
203
  return;
208
204
  }
209
205
  }
@@ -18,6 +18,9 @@ import { without_reactive_context } from './bindings/shared.js';
18
18
  */
19
19
  export const event_symbol = Symbol('events');
20
20
 
21
+ // The native listener boundary at which a delegated descendant stopped propagation.
22
+ const propagation_stopped_at = Symbol('propagation stopped at');
23
+
21
24
  /** @type {Set<string>} */
22
25
  export const all_registered_events = new Set();
23
26
 
@@ -62,7 +65,10 @@ export function create_event(event_name, dom, handler, options = {}) {
62
65
  // Only call in the bubble phase, else delegated events would be called before the capturing events
63
66
  handle_event_propagation.call(dom, event);
64
67
  }
65
- if (!event.cancelBubble) {
68
+ // Native stopPropagation() does not stop other listeners on the same element.
69
+ // Only skip this callback if a delegated descendant stopped before reaching it.
70
+ // @ts-expect-error
71
+ if (options.capture || event[propagation_stopped_at] !== dom) {
66
72
  return without_reactive_context(() => {
67
73
  return handler?.call(this, event);
68
74
  });
@@ -180,6 +186,19 @@ let last_propagated_event_clear_scheduled = false;
180
186
  */
181
187
  export function handle_event_propagation(event) {
182
188
  var handler_element = this;
189
+ var was_stopped = event.cancelBubble;
190
+
191
+ // Another listener at this boundary may already have dispatched the delegated
192
+ // handler that stopped propagation. Do not dispatch it again.
193
+ // @ts-expect-error
194
+ if (was_stopped && event[propagation_stopped_at] === handler_element) return;
195
+
196
+ if (!was_stopped) {
197
+ // The same event object may be dispatched again.
198
+ // @ts-expect-error
199
+ delete event[propagation_stopped_at];
200
+ }
201
+
183
202
  var owner_document = /** @type {Node} */ (handler_element).ownerDocument;
184
203
  var event_name = event.type;
185
204
  var path = event.composedPath?.() || [];
@@ -302,7 +321,13 @@ export function handle_event_propagation(event) {
302
321
  throw_error = error;
303
322
  }
304
323
  }
305
- if (event.cancelBubble) break;
324
+ if (event.cancelBubble) {
325
+ if (!was_stopped) {
326
+ // @ts-expect-error
327
+ event[propagation_stopped_at] = handler_element;
328
+ }
329
+ break;
330
+ }
306
331
 
307
332
  path_idx++;
308
333
  current_target = path_idx < path.length ? /** @type {Element} */ (path[path_idx]) : null;
@@ -5,7 +5,8 @@ import {
5
5
  HYDRATION_END,
6
6
  HYDRATION_ERROR,
7
7
  HYDRATION_START,
8
- HYDRATION_START_ELSE
8
+ HYDRATION_START_ELSE,
9
+ HYDRATION_START_FAILED
9
10
  } from '../../../constants.js';
10
11
  import * as w from '../warnings.js';
11
12
  import { get_next_sibling } from './operations.js';
@@ -98,6 +99,8 @@ export function skip_nodes(remove = true) {
98
99
  } else if (
99
100
  data === HYDRATION_START ||
100
101
  data === HYDRATION_START_ELSE ||
102
+ // "[?" followed by the serialized error, for failed boundaries
103
+ data.startsWith(HYDRATION_START_FAILED) ||
101
104
  // "[1", "[2", etc. for if blocks
102
105
  (data[0] === '[' && !isNaN(Number(data.slice(1))))
103
106
  ) {
@@ -13,7 +13,7 @@ import {
13
13
  TEXT_CACHE,
14
14
  TEXT_NODE
15
15
  } from '#client/constants';
16
- import { eager_block_effects } from '../reactivity/batch.js';
16
+ import { eager_block_writes } from '../reactivity/batch.js';
17
17
  import { NAMESPACE_HTML } from '../../../constants.js';
18
18
 
19
19
  // export these for reference in the compiled code, making global name deduplication unnecessary
@@ -245,8 +245,7 @@ export function clear_text_content(node) {
245
245
  * current `<svelte:boundary>`
246
246
  */
247
247
  export function should_defer_append() {
248
- if (!async_mode_flag) return false;
249
- if (eager_block_effects !== null) return false;
248
+ if (!async_mode_flag && eager_block_writes === null) return false;
250
249
 
251
250
  var flags = /** @type {Effect} */ (active_effect).f;
252
251
  return (flags & REACTION_RAN) !== 0;
@@ -4,7 +4,6 @@ import { hydrate_next, hydrate_node, hydrating, set_hydrate_node } from './hydra
4
4
  import {
5
5
  create_text,
6
6
  get_first_child,
7
- get_next_sibling,
8
7
  is_firefox,
9
8
  create_element,
10
9
  create_fragment,
@@ -1,18 +1,11 @@
1
- /** @import { Derived, Effect } from '#client' */
1
+ /** @import { Effect } from '#client' */
2
2
  /** @import { Boundary } from './dom/blocks/boundary.js' */
3
3
  import { DEV } from 'esm-env';
4
4
  import { FILENAME, HYDRATION_ERROR } from '../../constants.js';
5
5
  import { is_firefox } from './dom/operations.js';
6
- import {
7
- ERROR_VALUE,
8
- BOUNDARY_EFFECT,
9
- REACTION_RAN,
10
- EFFECT,
11
- DESTROYED,
12
- DESTROYING
13
- } from './constants.js';
6
+ import { BOUNDARY_EFFECT, REACTION_RAN, EFFECT, DESTROYED, DESTROYING } from './constants.js';
14
7
  import { define_property, get_descriptor } from '../shared/utils.js';
15
- import { active_effect, active_reaction } from './runtime.js';
8
+ import { active_effect } from './runtime.js';
16
9
 
17
10
  const adjustments = new WeakMap();
18
11
 
@@ -22,9 +15,8 @@ const adjustments = new WeakMap();
22
15
  export function handle_error(error) {
23
16
  var effect = active_effect;
24
17
 
25
- // for unowned deriveds, don't throw until we read the value
18
+ // for unowned deriveds, don't throw until we read the value (the error becomes their value)
26
19
  if (effect === null) {
27
- /** @type {Derived} */ (active_reaction).f |= ERROR_VALUE;
28
20
  return error;
29
21
  }
30
22
 
@@ -5,12 +5,12 @@ import { DEV } from 'esm-env';
5
5
  export * from '../shared/errors.js';
6
6
 
7
7
  /**
8
- * Cannot create a `$derived(...)` with an `await` expression outside of an effect tree
8
+ * Can only create a `$derived(...)` with an `await` expression during component initialization or in a declaration tag
9
9
  * @returns {never}
10
10
  */
11
11
  export function async_derived_orphan() {
12
12
  if (DEV) {
13
- const error = new Error(`async_derived_orphan\nCannot create a \`$derived(...)\` with an \`await\` expression outside of an effect tree\nhttps://svelte.dev/e/async_derived_orphan`);
13
+ const error = new Error(`async_derived_orphan\nCan only create a \`$derived(...)\` with an \`await\` expression during component initialization or in a declaration tag\nhttps://svelte.dev/e/async_derived_orphan`);
14
14
 
15
15
  error.name = 'Svelte error';
16
16
 
@@ -296,6 +296,22 @@ export function fork_timing() {
296
296
  }
297
297
  }
298
298
 
299
+ /**
300
+ * `getAbortSignal()` cannot be called after an `await`
301
+ * @returns {never}
302
+ */
303
+ export function get_abort_signal_after_await() {
304
+ if (DEV) {
305
+ const error = new Error(`get_abort_signal_after_await\n\`getAbortSignal()\` cannot be called after an \`await\`\nhttps://svelte.dev/e/get_abort_signal_after_await`);
306
+
307
+ error.name = 'Svelte error';
308
+
309
+ throw error;
310
+ } else {
311
+ throw new Error(`https://svelte.dev/e/get_abort_signal_after_await`);
312
+ }
313
+ }
314
+
299
315
  /**
300
316
  * `getAbortSignal()` can only be called inside an effect or derived
301
317
  * @returns {never}
@@ -119,7 +119,6 @@ export {
119
119
  derived_safe_equal
120
120
  } from './reactivity/deriveds.js';
121
121
  export {
122
- aborted,
123
122
  effect_tracking,
124
123
  effect_root,
125
124
  legacy_pre_effect,