svelte 5.57.2 → 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 (66) 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/2-analyze/visitors/shared/a11y/index.js +30 -5
  14. package/src/compiler/phases/3-transform/client/transform-template/index.js +27 -9
  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/Fragment.js +6 -1
  27. package/src/compiler/phases/3-transform/server/visitors/TitleElement.js +1 -1
  28. package/src/compiler/phases/3-transform/server/visitors/shared/element.js +2 -1
  29. package/src/compiler/phases/3-transform/server/visitors/shared/utils.js +1 -1
  30. package/src/compiler/phases/patterns.js +0 -1
  31. package/src/compiler/print/index.js +4 -16
  32. package/src/compiler/state.js +1 -1
  33. package/src/compiler/utils/builders.js +0 -1
  34. package/src/compiler/utils/mapped_code.js +1 -12
  35. package/src/constants.js +0 -8
  36. package/src/internal/client/dev/debug.js +14 -0
  37. package/src/internal/client/dev/elements.js +25 -9
  38. package/src/internal/client/dom/blocks/await.js +1 -2
  39. package/src/internal/client/dom/blocks/boundary.js +4 -7
  40. package/src/internal/client/dom/blocks/branches.js +2 -1
  41. package/src/internal/client/dom/blocks/html.js +44 -10
  42. package/src/internal/client/dom/blocks/slot.js +19 -1
  43. package/src/internal/client/dom/blocks/snippet.js +13 -0
  44. package/src/internal/client/dom/blocks/svelte-component.js +1 -1
  45. package/src/internal/client/dom/blocks/svelte-element.js +2 -1
  46. package/src/internal/client/dom/elements/attributes.js +12 -4
  47. package/src/internal/client/dom/elements/bindings/select.js +2 -1
  48. package/src/internal/client/dom/hydration.js +4 -1
  49. package/src/internal/client/dom/template.js +0 -1
  50. package/src/internal/client/proxy.js +2 -1
  51. package/src/internal/client/reactivity/async.js +2 -1
  52. package/src/internal/client/reactivity/batch.js +84 -127
  53. package/src/internal/client/reactivity/deriveds.js +2 -1
  54. package/src/internal/client/reactivity/equality.js +0 -9
  55. package/src/internal/client/reactivity/props.js +0 -1
  56. package/src/internal/client/reactivity/sources.js +5 -3
  57. package/src/internal/client/reactivity/utils.js +5 -6
  58. package/src/internal/server/errors.js +2 -2
  59. package/src/internal/server/renderer.js +52 -118
  60. package/src/internal/shared/utils.js +12 -0
  61. package/src/motion/spring.js +1 -1
  62. package/src/motion/tweened.js +1 -1
  63. package/src/reactivity/create-subscriber.js +1 -1
  64. package/src/version.js +1 -1
  65. package/types/index.d.ts +2 -2
  66. package/types/index.d.ts.map +1 -1
@@ -33,7 +33,7 @@ export function Fragment(node, context) {
33
33
  };
34
34
 
35
35
  for (const node of hoisted) {
36
- context.visit(node, state);
36
+ if (node.type !== 'TitleElement') context.visit(node, state);
37
37
  }
38
38
 
39
39
  if (is_text_first) {
@@ -43,6 +43,11 @@ export function Fragment(node, context) {
43
43
 
44
44
  process_children(trimmed, { ...context, state });
45
45
 
46
+ // the client sets titles after the rest of the fragment
47
+ for (const node of hoisted) {
48
+ if (node.type === 'TitleElement') context.visit(node, state);
49
+ }
50
+
46
51
  if (state.async_consts && state.async_consts.thunks.length > 0) {
47
52
  state.init.push(
48
53
  b.var(state.async_consts.id, b.call('$$renderer.run', b.array(state.async_consts.thunks)))
@@ -13,7 +13,7 @@ export function TitleElement(node, context) {
13
13
  process_children(node.fragment.nodes, { ...context, state: { ...context.state, template } });
14
14
  template.push(b.literal('</title>'));
15
15
 
16
- context.state.init.push(
16
+ context.state.template.push(
17
17
  b.stmt(
18
18
  b.call('$$renderer.title', b.arrow([b.id('$$renderer')], b.block(build_template(template))))
19
19
  )
@@ -1,9 +1,10 @@
1
1
  /** @import { ArrayExpression, Expression, Literal, ObjectExpression } from 'estree' */
2
2
  /** @import { AST } from '#compiler' */
3
3
  /** @import { ComponentContext, ComponentServerTransformState } from '../../types.js' */
4
+ /** @import { ExpressionMetadata } from '../../../../nodes.js' */
4
5
  import { is_event_attribute, is_text_attribute } from '../../../../../utils/ast.js';
5
6
  import { binding_properties } from '../../../../bindings.js';
6
- import { ExpressionMetadata, is_custom_element_node } from '../../../../nodes.js';
7
+ import { is_custom_element_node } from '../../../../nodes.js';
7
8
  import { regex_starts_with_newline } from '../../../../patterns.js';
8
9
  import * as b from '#compiler/builders';
9
10
  import {
@@ -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';
@@ -514,3 +514,17 @@ export function log_inconsistent_branches(effect) {
514
514
 
515
515
  return true;
516
516
  }
517
+
518
+ /**
519
+ * Stringify a derived function, removing `$.track_reactivity_loss` and `$.get` etc
520
+ * @param {Function} fn
521
+ */
522
+ export function stringify_derived(fn) {
523
+ return `{${fn
524
+ .toString()
525
+ .replace(/^async \(\) => /, '')
526
+ .replace(/^\(/, '')
527
+ .replace(/\$\.get\((.+?)\)/g, (_, name) => name)
528
+ .replace(/\$\.track_reactivity_loss\((.+?)\)\(\)/g, (_, name) => name)
529
+ .replace(/\)$/, '')}}`;
530
+ }
@@ -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';
@@ -112,11 +112,8 @@ export class Boundary {
112
112
  #pending_count = 0;
113
113
  #pending_count_update_queued = false;
114
114
 
115
- /** @type {Set<Effect>} */
116
- #dirty_effects = new Set();
117
-
118
- /** @type {Set<Effect>} */
119
- #maybe_dirty_effects = new Set();
115
+ /** @type {Map<Effect, number>} */
116
+ #dirty_reactions = new Map();
120
117
 
121
118
  /**
122
119
  * A source containing the number of pending async deriveds/expressions.
@@ -358,7 +355,7 @@ export class Boundary {
358
355
 
359
356
  // any effects that were previously deferred should be transferred
360
357
  // to the batch, which will flush in the next microtask
361
- batch.transfer_effects(this.#dirty_effects, this.#maybe_dirty_effects);
358
+ batch.transfer_reactions(this.#dirty_reactions);
362
359
  }
363
360
 
364
361
  /**
@@ -366,7 +363,7 @@ export class Boundary {
366
363
  * @param {Effect} effect
367
364
  */
368
365
  defer_effect(effect) {
369
- defer_effect(effect, this.#dirty_effects, this.#maybe_dirty_effects);
366
+ defer_effect(effect, this.#dirty_reactions);
370
367
  }
371
368
 
372
369
  /**
@@ -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 {
@@ -178,7 +178,8 @@ export function set_attribute(element, attribute, value, skip_warning) {
178
178
  }
179
179
  }
180
180
 
181
- if (attributes[attribute] === (attributes[attribute] = value)) return;
181
+ var previous = attributes[attribute];
182
+ if (previous === (attributes[attribute] = value)) return;
182
183
 
183
184
  if (attribute === 'loading') {
184
185
  // @ts-expect-error
@@ -190,7 +191,14 @@ export function set_attribute(element, attribute, value, skip_warning) {
190
191
  } else if (typeof value !== 'string' && get_setters(element).has(attribute)) {
191
192
  // @ts-ignore
192
193
  element[attribute] = value;
193
- } else {
194
+ } else if (
195
+ // while hydrating, skip a number or boolean whose string the server already rendered
196
+ !(
197
+ hydrating &&
198
+ (typeof value === 'number' || typeof value === 'boolean') &&
199
+ previous === String(value)
200
+ )
201
+ ) {
194
202
  element.setAttribute(attribute, value);
195
203
  }
196
204
  }
@@ -343,7 +351,7 @@ function set_attributes(
343
351
  // the value is set to the text content of the option element, and setting the value
344
352
  // to null or undefined means the value is set to the string "null" or "undefined".
345
353
  // To align with how we handle this case in non-spread-scenarios, this logic is needed.
346
- // 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:
347
355
  // Because of the "set missing props to null" logic above, we can't differentiate
348
356
  // between a missing value and an explicitly set value of null or undefined. That means
349
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,
@@ -241,7 +241,8 @@ export function proxy(value) {
241
241
 
242
242
  if (
243
243
  s !== undefined ||
244
- (active_effect !== null && (!has || get_descriptor(target, prop)?.writable))
244
+ ((active_effect !== null || active_reaction !== null) &&
245
+ (!has || get_descriptor(target, prop)?.writable))
245
246
  ) {
246
247
  if (s === undefined) {
247
248
  s = with_parent(() => {
@@ -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,