svelte 5.57.3 → 5.58.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 (59) 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/visitors/EachBlock.js +1 -1
  15. package/src/compiler/phases/3-transform/client/visitors/Fragment.js +13 -1
  16. package/src/compiler/phases/3-transform/client/visitors/HtmlTag.js +10 -2
  17. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +11 -2
  18. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +15 -7
  19. package/src/compiler/phases/3-transform/client/visitors/SlotElement.js +19 -1
  20. package/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +0 -1
  21. package/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +1 -1
  22. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +1 -1
  23. package/src/compiler/phases/3-transform/client/visitors/shared/events.js +1 -1
  24. package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +1 -1
  25. package/src/compiler/phases/3-transform/server/visitors/Fragment.js +6 -1
  26. package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +1 -1
  27. package/src/compiler/phases/3-transform/server/visitors/shared/element.js +2 -1
  28. package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +1 -1
  29. package/src/compiler/phases/patterns.js +0 -1
  30. package/src/compiler/print/index.js +4 -16
  31. package/src/compiler/state.js +1 -1
  32. package/src/compiler/utils/builders.js +0 -1
  33. package/src/compiler/utils/mapped_code.js +1 -12
  34. package/src/constants.js +0 -8
  35. package/src/internal/client/dev/elements.js +25 -9
  36. package/src/internal/client/dom/blocks/await.js +1 -2
  37. package/src/internal/client/dom/blocks/branches.js +2 -1
  38. package/src/internal/client/dom/blocks/html.js +44 -10
  39. package/src/internal/client/dom/blocks/slot.js +19 -1
  40. package/src/internal/client/dom/blocks/snippet.js +13 -0
  41. package/src/internal/client/dom/blocks/svelte-component.js +1 -1
  42. package/src/internal/client/dom/blocks/svelte-element.js +2 -1
  43. package/src/internal/client/dom/elements/attributes.js +2 -2
  44. package/src/internal/client/dom/elements/bindings/select.js +2 -1
  45. package/src/internal/client/dom/hydration.js +4 -1
  46. package/src/internal/client/dom/template.js +0 -1
  47. package/src/internal/client/reactivity/async.js +2 -1
  48. package/src/internal/client/reactivity/batch.js +14 -15
  49. package/src/internal/client/reactivity/equality.js +0 -9
  50. package/src/internal/client/reactivity/props.js +0 -1
  51. package/src/internal/client/reactivity/sources.js +3 -1
  52. package/src/internal/server/renderer.js +52 -118
  53. package/src/internal/shared/utils.js +12 -0
  54. package/src/motion/spring.js +1 -1
  55. package/src/motion/tweened.js +1 -1
  56. package/src/reactivity/create-subscriber.js +1 -1
  57. package/src/version.js +1 -1
  58. package/types/index.d.ts +2 -2
  59. package/types/index.d.ts.map +1 -1
@@ -1,6 +1,7 @@
1
1
  /** @import { Expression, Identifier, Node, Statement, BlockStatement, ArrayExpression } from 'estree' */
2
2
  /** @import { AST } from '#compiler' */
3
3
  /** @import { ComponentContext, ServerTransformState } from '../../types.js' */
4
+ /** @import { ExpressionMetadata } from '../../../../nodes.js' */
4
5
 
5
6
  import { escape_html } from '../../../../../../escaping.js';
6
7
  import {
@@ -13,7 +14,6 @@ import * as b from '#compiler/builders';
13
14
  import { sanitize_template_string } from '../../../../../utils/sanitize_template_string.js';
14
15
  import { regex_whitespaces_strict } from '../../../../patterns.js';
15
16
  import { has_await_expression, save } from '../../../../../utils/ast.js';
16
- import { ExpressionMetadata } from '../../../../nodes.js';
17
17
 
18
18
  /** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
19
19
  export const block_open = b.literal(BLOCK_OPEN);
@@ -1,4 +1,3 @@
1
- export const regex_whitespace = /\s/;
2
1
  export const regex_whitespaces = /\s+/;
3
2
  export const regex_starts_with_newline = /^\r?\n/;
4
3
  export const regex_starts_with_whitespace = /^\s/;
@@ -707,10 +707,7 @@ const svelte_visitors = (comments, state) => ({
707
707
 
708
708
  AnimateDirective(node, context) {
709
709
  context.write(`animate:${node.name}`);
710
- if (
711
- node.expression !== null &&
712
- !(node.expression.type === 'Identifier' && node.expression.name === node.name)
713
- ) {
710
+ if (node.expression !== null) {
714
711
  context.write('={');
715
712
  context.visit(node.expression);
716
713
  context.write('}');
@@ -994,10 +991,7 @@ const svelte_visitors = (comments, state) => ({
994
991
  for (const modifier of node.modifiers) {
995
992
  context.write(`|${modifier}`);
996
993
  }
997
- if (
998
- node.expression !== null &&
999
- !(node.expression.type === 'Identifier' && node.expression.name === node.name)
1000
- ) {
994
+ if (node.expression !== null) {
1001
995
  context.write('={');
1002
996
  context.visit(node.expression);
1003
997
  context.write('}');
@@ -1144,10 +1138,7 @@ const svelte_visitors = (comments, state) => ({
1144
1138
  for (const modifier of node.modifiers) {
1145
1139
  context.write(`|${modifier}`);
1146
1140
  }
1147
- if (
1148
- node.expression !== null &&
1149
- !(node.expression.type === 'Identifier' && node.expression.name === node.name)
1150
- ) {
1141
+ if (node.expression !== null) {
1151
1142
  context.write('={');
1152
1143
  context.visit(node.expression);
1153
1144
  context.write('}');
@@ -1156,10 +1147,7 @@ const svelte_visitors = (comments, state) => ({
1156
1147
 
1157
1148
  UseDirective(node, context) {
1158
1149
  context.write(`use:${node.name}`);
1159
- if (
1160
- node.expression !== null &&
1161
- !(node.expression.type === 'Identifier' && node.expression.name === node.name)
1162
- ) {
1150
+ if (node.expression !== null) {
1163
1151
  context.write('={');
1164
1152
  context.visit(node.expression);
1165
1153
  context.write('}');
@@ -174,6 +174,6 @@ export function adjust(state) {
174
174
  }
175
175
 
176
176
  ignore_stack = [];
177
- ignore_map.clear();
177
+ ignore_map = new Map(); // faster than .clear()
178
178
  cached_ignore_snapshot = null;
179
179
  }
@@ -1,5 +1,4 @@
1
1
  /** @import * as ESTree from 'estree' */
2
- import { walk } from 'zimmerframe';
3
2
  import { regex_is_valid_identifier } from '../phases/patterns.js';
4
3
  import { sanitize_template_string } from './sanitize_template_string.js';
5
4
  import { has_await_expression } from './ast.js';
@@ -5,6 +5,7 @@
5
5
  /** @import { Source } from '../preprocess/private.js' */
6
6
  /** @import { DecodedSourceMap, SourceMapSegment, RawSourceMap } from '@jridgewell/remapping' */
7
7
  import remapping from '@jridgewell/remapping';
8
+ import { push_array } from '../../internal/shared/utils.js';
8
9
 
9
10
  /**
10
11
  * @param {string} s
@@ -12,18 +13,6 @@ import remapping from '@jridgewell/remapping';
12
13
  function last_line_length(s) {
13
14
  return s.length - s.lastIndexOf('\n') - 1;
14
15
  }
15
-
16
- /**
17
- * `array.push(...items)` overflows the stack for large `items`.
18
- * @template T
19
- * @param {T[]} array
20
- * @param {T[]} items
21
- */
22
- function push_array(array, items) {
23
- for (let i = 0; i < items.length; i++) {
24
- array.push(items[i]);
25
- }
26
- }
27
16
  // mutate map in-place
28
17
 
29
18
  /**
package/src/constants.js CHANGED
@@ -55,12 +55,4 @@ export const IGNORABLE_RUNTIME_WARNINGS = /** @type {const} */ ([
55
55
  'ownership_invalid_mutation'
56
56
  ]);
57
57
 
58
- /**
59
- * Whitespace inside one of these elements will not result in
60
- * a whitespace node being created in any circumstances. (This
61
- * list is almost certainly very incomplete)
62
- * TODO this is currently unused
63
- */
64
- export const ELEMENTS_WITHOUT_TEXT = ['audio', 'datalist', 'dl', 'optgroup', 'select', 'video'];
65
-
66
58
  export const ATTACHMENT_KEY = '@attach';
@@ -2,23 +2,37 @@
2
2
  import { COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, ELEMENT_NODE } from '#client/constants';
3
3
  import { HYDRATION_END, HYDRATION_START } from '../../../constants.js';
4
4
  import { hydrating } from '../dom/hydration.js';
5
- import { dev_stack } from '../context.js';
5
+ import { component_context, dev_stack } from '../context.js';
6
6
 
7
7
  /**
8
- * @param {any} fn
8
+ * Assign locations immediately after cloning, before blocks or child components insert elements.
9
+ * During hydration, the compiler calls the factory's `hydrate_assign_locations` method after the
10
+ * template's children have their own locations and can be skipped.
11
+ * @param {() => DocumentFragment | Element} fn
9
12
  * @param {string} filename
10
13
  * @param {SourceLocation[]} locations
11
- * @returns {any}
12
14
  */
13
15
  export function add_locations(fn, filename, locations) {
14
- return (/** @type {any[]} */ ...args) => {
15
- const dom = fn(...args);
16
+ var create = () => {
17
+ var dom = fn();
16
18
 
17
- var node = hydrating ? dom : dom.nodeType === DOCUMENT_FRAGMENT_NODE ? dom.firstChild : dom;
18
- assign_locations(node, filename, locations);
19
+ if (!hydrating) {
20
+ assign_locations(
21
+ dom.nodeType === DOCUMENT_FRAGMENT_NODE ? dom.firstChild : dom,
22
+ filename,
23
+ locations
24
+ );
25
+ }
19
26
 
20
27
  return dom;
21
28
  };
29
+
30
+ create.hydrate_assign_locations = (/** @type {Node} */ node) => {
31
+ // Pass the node explicitly because the same factory can be called repeatedly (e.g. in each blocks).
32
+ if (hydrating) assign_locations(node, filename, locations);
33
+ };
34
+
35
+ return create;
22
36
  }
23
37
 
24
38
  /**
@@ -30,7 +44,8 @@ function assign_location(element, filename, location) {
30
44
  // @ts-expect-error
31
45
  element.__svelte_meta = {
32
46
  parent: dev_stack,
33
- loc: { file: filename, line: location[0], column: location[1] }
47
+ loc: { file: filename, line: location[0], column: location[1] },
48
+ component: component_context
34
49
  };
35
50
 
36
51
  if (location[2]) {
@@ -54,7 +69,8 @@ function assign_locations(node, filename, locations) {
54
69
  else if (comment.data[0] === HYDRATION_END) depth -= 1;
55
70
  }
56
71
 
57
- if (depth === 0 && node.nodeType === ELEMENT_NODE) {
72
+ // @ts-expect-error
73
+ if (depth === 0 && node.nodeType === ELEMENT_NODE && !node.__svelte_meta) {
58
74
  assign_location(/** @type {Element} */ (node), filename, locations[i++]);
59
75
  }
60
76
 
@@ -7,8 +7,7 @@ import {
7
7
  hydrating,
8
8
  skip_nodes,
9
9
  set_hydrate_node,
10
- set_hydrating,
11
- hydrate_node
10
+ set_hydrating
12
11
  } from '../hydration.js';
13
12
  import { queue_micro_task } from '../task.js';
14
13
  import { HYDRATION_START_ELSE, UNINITIALIZED } from '../../../../constants.js';
@@ -1,5 +1,6 @@
1
1
  /** @import { Effect, TemplateNode } from '#client' */
2
- import { Batch, current_batch } from '../../reactivity/batch.js';
2
+ /** @import { Batch } from '../../reactivity/batch.js' */
3
+ import { current_batch } from '../../reactivity/batch.js';
3
4
  import {
4
5
  branch,
5
6
  destroy_effect,
@@ -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
 
@@ -2,7 +2,7 @@
2
2
  import { DEV } from 'esm-env';
3
3
  import { hydrating, set_hydrating } from '../hydration.js';
4
4
  import { get_descriptors, get_prototype_of } from '../../../shared/utils.js';
5
- import { create_event, delegate, delegated, event, event_symbol } from './events.js';
5
+ import { create_event, delegate, delegated } from './events.js';
6
6
  import { add_form_reset_listener, autofocus } from './misc.js';
7
7
  import * as w from '../../warnings.js';
8
8
  import {
@@ -351,7 +351,7 @@ function set_attributes(
351
351
  // the value is set to the text content of the option element, and setting the value
352
352
  // to null or undefined means the value is set to the string "null" or "undefined".
353
353
  // 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:
354
+ // There's a super-edge-case bug here that is left in favor of smaller code size:
355
355
  // Because of the "set missing props to null" logic above, we can't differentiate
356
356
  // between a missing value and an explicitly set value of null or undefined. That means
357
357
  // that once set, the value attribute of an <option> element can't be removed. This is
@@ -1,9 +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 { current_batch, previous_batch } from '../../../reactivity/batch.js';
7
8
  import { async_mode_flag } from '../../../../flags/index.js';
8
9
 
9
10
  /**
@@ -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
  ) {
@@ -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,4 +1,5 @@
1
1
  /** @import { Blocker, Effect, Source, Value } from '#client' */
2
+ /** @import { Batch } from './batch.js' */
2
3
  import { DESTROYED, STALE_REACTION } from '#client/constants';
3
4
  import { DEV } from 'esm-env';
4
5
  import {
@@ -15,7 +16,7 @@ import {
15
16
  set_active_effect,
16
17
  set_active_reaction
17
18
  } from '../runtime.js';
18
- import { Batch, current_batch } from './batch.js';
19
+ import { current_batch } from './batch.js';
19
20
  import {
20
21
  async_derived,
21
22
  reactivity_loss_tracker,
@@ -38,7 +38,6 @@ import { defer_effect } from './utils.js';
38
38
  import { UNINITIALIZED } from '../../../constants.js';
39
39
  import { set_signal_status } from './status.js';
40
40
  import { invariant } from '../../shared/dev.js';
41
- import { log_effect_tree } from '../dev/debug.js';
42
41
  import { OBSOLETE } from './deriveds.js';
43
42
 
44
43
  /** @type {Batch | null} */
@@ -89,8 +88,8 @@ export let legacy_updates = null;
89
88
 
90
89
  var flush_count = 0;
91
90
 
92
- /** @type {Set<Value>} */
93
- var source_stacks = new Set();
91
+ /** Sources whose DEV update counts and stack traces need resetting after the flush. @type {Set<Value>} */
92
+ export const source_stacks = new Set();
94
93
 
95
94
  let uid = 1;
96
95
 
@@ -323,14 +322,6 @@ export class Batch {
323
322
  #process() {
324
323
  this.started = true;
325
324
 
326
- if (DEV) {
327
- // track all the values that were updated during this flush,
328
- // so that they can be reset afterwards
329
- for (const value of this.current.keys()) {
330
- source_stacks.add(value);
331
- }
332
- }
333
-
334
325
  // We always reschedule previously-deferred effects, not just when
335
326
  // #is_deferred() is true, because traversing the tree could make
336
327
  // an if block that contains the last blocking pending effect falsy,
@@ -377,6 +368,16 @@ export class Batch {
377
368
  throw e;
378
369
  }
379
370
  }
371
+
372
+ if (this.#scheduled.length > 0) {
373
+ // A later traversal may discover effects before ones we already collected.
374
+ // Recollect them together so they are flushed in tree order, rather than
375
+ // appending earlier effects after their later siblings.
376
+ for (const effect of render_effects) this.#scheduled.push(effect);
377
+ for (const effect of effects) this.#scheduled.push(effect);
378
+ render_effects.length = 0;
379
+ effects.length = 0;
380
+ }
380
381
  }
381
382
 
382
383
  // any writes should take effect in a subsequent batch
@@ -638,10 +639,6 @@ export class Batch {
638
639
 
639
640
  flush() {
640
641
  try {
641
- if (DEV) {
642
- source_stacks.clear();
643
- }
644
-
645
642
  is_processing = true;
646
643
  current_batch = this;
647
644
 
@@ -662,6 +659,8 @@ export class Batch {
662
659
  for (const source of source_stacks) {
663
660
  source.updated = null;
664
661
  }
662
+
663
+ source_stacks.clear();
665
664
  }
666
665
  }
667
666
  }
@@ -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
@@ -37,7 +37,8 @@ import {
37
37
  batch_values,
38
38
  eager_block_effects,
39
39
  schedule_effect,
40
- legacy_updates
40
+ legacy_updates,
41
+ source_stacks
41
42
  } from './batch.js';
42
43
  import { proxy } from '../proxy.js';
43
44
  import { execute_derived } from './deriveds.js';
@@ -202,6 +203,7 @@ export function internal_set(source, value, updated_during_traversal = null) {
202
203
  if (DEV) {
203
204
  if (tracing_mode_flag || active_effect !== null) {
204
205
  source.updated ??= new Map();
206
+ source_stacks.add(source);
205
207
 
206
208
  // For performance reasons, when not using $inspect.trace, we only start collecting stack traces
207
209
  // after the same source has been updated more than 5 times in the same flush cycle.