svelte 5.58.0 → 5.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/compiler/index.js +1 -1
  2. package/package.json +19 -1
  3. package/renderer.d.ts +1 -0
  4. package/src/compiler/errors.js +19 -0
  5. package/src/compiler/index.js +37 -2
  6. package/src/compiler/migrate/index.js +2 -1
  7. package/src/compiler/phases/1-parse/read/options.js +20 -0
  8. package/src/compiler/phases/2-analyze/index.js +21 -2
  9. package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +5 -0
  10. package/src/compiler/phases/2-analyze/visitors/Attribute.js +6 -2
  11. package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -0
  12. package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +2 -1
  13. package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +5 -0
  14. package/src/compiler/phases/2-analyze/visitors/OnDirective.js +6 -0
  15. package/src/compiler/phases/2-analyze/visitors/RegularElement.js +13 -6
  16. package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +5 -0
  17. package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +5 -0
  18. package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +5 -1
  19. package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +5 -0
  20. package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +5 -0
  21. package/src/compiler/phases/2-analyze/visitors/Text.js +3 -1
  22. package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +6 -0
  23. package/src/compiler/phases/2-analyze/visitors/shared/element.js +3 -2
  24. package/src/compiler/phases/3-transform/client/transform-client.js +68 -1
  25. package/src/compiler/phases/3-transform/client/transform-template/index.js +4 -3
  26. package/src/compiler/phases/3-transform/client/transform-template/template.js +1 -1
  27. package/src/compiler/phases/3-transform/client/utils.js +3 -2
  28. package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +23 -13
  29. package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +13 -1
  30. package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +11 -1
  31. package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +8 -5
  32. package/src/compiler/phases/3-transform/client/visitors/shared/component.js +17 -8
  33. package/src/compiler/phases/3-transform/client/visitors/shared/element.js +4 -3
  34. package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +7 -1
  35. package/src/compiler/phases/3-transform/server/transform-server.js +14 -1
  36. package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +8 -0
  37. package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +8 -4
  38. package/src/compiler/print/index.js +45 -57
  39. package/src/compiler/state.js +12 -0
  40. package/src/compiler/utils/builders.js +2 -2
  41. package/src/compiler/validate-options.js +47 -1
  42. package/src/index-client.js +3 -3
  43. package/src/internal/client/constants.js +15 -1
  44. package/src/internal/client/custom-renderer/containers.js +213 -0
  45. package/src/internal/client/custom-renderer/cross.js +145 -0
  46. package/src/internal/client/custom-renderer/index.js +28 -0
  47. package/src/internal/client/custom-renderer/state.js +59 -0
  48. package/src/internal/client/dev/css.js +3 -1
  49. package/src/internal/client/dev/debug.js +6 -6
  50. package/src/internal/client/dev/elements.js +9 -7
  51. package/src/internal/client/dev/tracing.js +67 -11
  52. package/src/internal/client/dev/validation.js +2 -1
  53. package/src/internal/client/dom/blocks/async.js +2 -1
  54. package/src/internal/client/dom/blocks/await.js +110 -19
  55. package/src/internal/client/dom/blocks/boundary.js +142 -88
  56. package/src/internal/client/dom/blocks/branches.js +94 -75
  57. package/src/internal/client/dom/blocks/css-props.js +31 -3
  58. package/src/internal/client/dom/blocks/each.js +166 -45
  59. package/src/internal/client/dom/blocks/html.js +19 -13
  60. package/src/internal/client/dom/blocks/slot.js +3 -3
  61. package/src/internal/client/dom/blocks/snippet.js +52 -3
  62. package/src/internal/client/dom/blocks/svelte-element.js +17 -6
  63. package/src/internal/client/dom/blocks/svelte-head.js +13 -4
  64. package/src/internal/client/dom/css.js +4 -4
  65. package/src/internal/client/dom/elements/attributes.js +91 -51
  66. package/src/internal/client/dom/elements/bindings/input.js +19 -10
  67. package/src/internal/client/dom/elements/bindings/select.js +13 -9
  68. package/src/internal/client/dom/elements/class.js +16 -5
  69. package/src/internal/client/dom/elements/events.js +153 -21
  70. package/src/internal/client/dom/elements/misc.js +3 -2
  71. package/src/internal/client/dom/elements/style.js +17 -6
  72. package/src/internal/client/dom/hydration.js +6 -6
  73. package/src/internal/client/dom/operations.js +435 -14
  74. package/src/internal/client/dom/reconciler.js +2 -2
  75. package/src/internal/client/dom/template.js +94 -66
  76. package/src/internal/client/error-handling.js +4 -12
  77. package/src/internal/client/errors.js +85 -2
  78. package/src/internal/client/index.js +9 -2
  79. package/src/internal/client/reactivity/async.js +257 -122
  80. package/src/internal/client/reactivity/batch.js +1124 -531
  81. package/src/internal/client/reactivity/deriveds.js +281 -177
  82. package/src/internal/client/reactivity/effects.js +87 -54
  83. package/src/internal/client/reactivity/sources.js +30 -124
  84. package/src/internal/client/reactivity/status.js +1 -1
  85. package/src/internal/client/render.js +60 -87
  86. package/src/internal/client/runtime.js +931 -153
  87. package/src/internal/client/validate.js +2 -2
  88. package/src/internal/disclose-version.js +1 -1
  89. package/src/internal/flags/custom-renderer-server.js +10 -0
  90. package/src/internal/flags/custom-renderer.js +3 -0
  91. package/src/internal/flags/index.js +6 -0
  92. package/src/internal/init-operations.js +3 -0
  93. package/src/internal/shared/errors.js +20 -0
  94. package/src/legacy/legacy-client.js +6 -2
  95. package/src/renderer/index-server.js +18 -0
  96. package/src/renderer/index.js +2 -0
  97. package/src/version.js +1 -1
  98. package/types/index.d.ts +245 -25
  99. package/types/index.d.ts.map +10 -1
  100. package/src/internal/client/reactivity/utils.js +0 -18
@@ -1,4 +1,5 @@
1
- /** @import { Blocker, 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';
@@ -33,6 +34,19 @@ import {
33
34
  set_selected
34
35
  } from './bindings/select.js';
35
36
  import { flatten } from '../../reactivity/async.js';
37
+ import {
38
+ has_attribute,
39
+ get_attribute,
40
+ remove_attribute,
41
+ set_attribute as set_attribute_op,
42
+ remove_event_listener,
43
+ node_name,
44
+ set_element_value,
45
+ set_element_checked,
46
+ set_element_default_value,
47
+ set_element_default_checked
48
+ } from '../operations.js';
49
+ import { current_renderer } from '../../custom-renderer/state.js';
36
50
 
37
51
  export const CLASS = Symbol('class');
38
52
  export const STYLE = Symbol('style');
@@ -55,6 +69,8 @@ const PROGRESS_TAG = IS_XHTML ? 'progress' : 'PROGRESS';
55
69
  export function remove_input_defaults(input) {
56
70
  if (!hydrating) return;
57
71
 
72
+ // we should be safe here from custom renderers as this only run during hydration
73
+
58
74
  var already_removed = false;
59
75
 
60
76
  // We try and remove the default attributes later, rather than sync during hydration.
@@ -66,13 +82,13 @@ export function remove_input_defaults(input) {
66
82
  already_removed = true;
67
83
 
68
84
  // Remove the attributes but preserve the values
69
- if (input.hasAttribute('value')) {
85
+ if (has_attribute(input, 'value')) {
70
86
  var value = input.value;
71
87
  set_attribute(input, 'value', null);
72
88
  input.value = value;
73
89
  }
74
90
 
75
- if (input.hasAttribute('checked')) {
91
+ if (has_attribute(input, 'checked')) {
76
92
  var checked = input.checked;
77
93
  set_attribute(input, 'checked', null);
78
94
  input.checked = checked;
@@ -96,15 +112,15 @@ export function set_value(element, value) {
96
112
  (attributes.value =
97
113
  // treat null and undefined the same for the initial value
98
114
  value ?? undefined) ||
99
- // @ts-expect-error
100
115
  // `progress` elements always need their value set when it's `0`
101
- (element.value === value && (value !== 0 || element.nodeName !== PROGRESS_TAG))
116
+ (current_renderer == null &&
117
+ /** @type {any} */ (element).value === value &&
118
+ (value !== 0 || node_name(element) !== PROGRESS_TAG))
102
119
  ) {
103
120
  return;
104
121
  }
105
122
 
106
- // @ts-expect-error
107
- element.value = value ?? '';
123
+ set_element_value(element, value);
108
124
  }
109
125
 
110
126
  /**
@@ -123,8 +139,7 @@ export function set_checked(element, checked) {
123
139
  return;
124
140
  }
125
141
 
126
- // @ts-expect-error
127
- element.checked = checked;
142
+ set_element_checked(element, checked);
128
143
  }
129
144
 
130
145
  /**
@@ -133,9 +148,7 @@ export function set_checked(element, checked) {
133
148
  * @param {boolean} checked
134
149
  */
135
150
  export function set_default_checked(element, checked) {
136
- const existing_value = element.checked;
137
- element.defaultChecked = checked;
138
- element.checked = existing_value;
151
+ set_element_default_checked(element, checked);
139
152
  }
140
153
 
141
154
  /**
@@ -144,9 +157,7 @@ export function set_default_checked(element, checked) {
144
157
  * @param {string} value
145
158
  */
146
159
  export function set_default_value(element, value) {
147
- const existing_value = element.value;
148
- element.defaultValue = value;
149
- element.value = existing_value;
160
+ set_element_default_value(element, value);
150
161
  }
151
162
 
152
163
  /**
@@ -159,12 +170,12 @@ export function set_attribute(element, attribute, value, skip_warning) {
159
170
  var attributes = get_attributes(element);
160
171
 
161
172
  if (hydrating) {
162
- attributes[attribute] = element.getAttribute(attribute);
173
+ attributes[attribute] = get_attribute(element, attribute);
163
174
 
164
175
  if (
165
176
  attribute === 'src' ||
166
177
  attribute === 'srcset' ||
167
- (attribute === 'href' && element.nodeName === LINK_TAG)
178
+ (attribute === 'href' && node_name(element) === LINK_TAG)
168
179
  ) {
169
180
  if (!skip_warning) {
170
181
  check_src_in_dev_hydration(element, attribute, value ?? '');
@@ -187,7 +198,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
187
198
  }
188
199
 
189
200
  if (value == null) {
190
- element.removeAttribute(attribute);
201
+ remove_attribute(element, attribute);
191
202
  } else if (typeof value !== 'string' && get_setters(element).has(attribute)) {
192
203
  // @ts-ignore
193
204
  element[attribute] = value;
@@ -199,7 +210,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
199
210
  previous === String(value)
200
211
  )
201
212
  ) {
202
- element.setAttribute(attribute, value);
213
+ set_attribute_op(element, attribute, value);
203
214
  }
204
215
  }
205
216
 
@@ -209,6 +220,7 @@ export function set_attribute(element, attribute, value, skip_warning) {
209
220
  * @param {string} value
210
221
  */
211
222
  export function set_xlink_attribute(dom, attribute, value) {
223
+ // custom renderer safe since we never emit this
212
224
  dom.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);
213
225
  }
214
226
 
@@ -218,6 +230,7 @@ export function set_xlink_attribute(dom, attribute, value) {
218
230
  * @param {any} value
219
231
  */
220
232
  export function set_custom_element_data(node, prop, value) {
233
+ // custom renderer safe since we never emit this
221
234
  // We need to ensure that setting custom element props, which can
222
235
  // invoke lifecycle methods on other custom elements, does not also
223
236
  // associate those lifecycle methods with the current active reaction
@@ -242,10 +255,10 @@ export function set_custom_element_data(node, prop, value) {
242
255
  // Don't compute setters for custom elements while they aren't registered yet,
243
256
  // because during their upgrade/instantiation they might add more setters.
244
257
  // Instead, fall back to a simple "an object, then set as property" heuristic.
245
- (setters_cache.has(node.getAttribute('is') || node.nodeName) ||
258
+ (setters_cache.has(get_attribute(node, 'is') || node_name(node)) ||
246
259
  // customElements may not be available in browser extension contexts
247
260
  !customElements ||
248
- customElements.get(node.getAttribute('is') || node.nodeName.toLowerCase())
261
+ customElements.get(get_attribute(node, 'is') || node_name(node).toLowerCase())
249
262
  ? get_setters(node).has(prop)
250
263
  : value && typeof value === 'object')
251
264
  ) {
@@ -284,7 +297,7 @@ function set_attributes(
284
297
  should_remove_defaults = false,
285
298
  skip_warning = false
286
299
  ) {
287
- if (hydrating && should_remove_defaults && element.nodeName === INPUT_TAG) {
300
+ if (hydrating && should_remove_defaults && node_name(element) === INPUT_TAG) {
288
301
  if (!('defaultValue' in next || 'defaultChecked' in next)) {
289
302
  remove_input_defaults(/** @type {HTMLInputElement} */ (element));
290
303
  }
@@ -303,8 +316,8 @@ function set_attributes(
303
316
  }
304
317
 
305
318
  var current = prev || {};
306
- var is_option_element = element.nodeName === OPTION_TAG;
307
- var is_select_element = element.nodeName === SELECT_TAG;
319
+ var is_option_element = node_name(element) === OPTION_TAG;
320
+ var is_select_element = node_name(element) === SELECT_TAG;
308
321
 
309
322
  try {
310
323
  for (var key in prev) {
@@ -327,7 +340,9 @@ function set_attributes(
327
340
  var setters = get_setters(element);
328
341
 
329
342
  if (
330
- element.nodeName === INPUT_TAG &&
343
+ // the following logic only makes sense in a DOM environment
344
+ current_renderer == null &&
345
+ node_name(element) === INPUT_TAG &&
331
346
  'type' in next &&
332
347
  ('value' in next || '__value' in next)
333
348
  ) {
@@ -364,7 +379,7 @@ function set_attributes(
364
379
  }
365
380
 
366
381
  if (key === 'class') {
367
- var is_html = element.namespaceURI === 'http://www.w3.org/1999/xhtml';
382
+ var is_html = current_renderer == null && element.namespaceURI === NAMESPACE_HTML;
368
383
  set_class(element, is_html, value, css_hash, prev?.[CLASS], next[CLASS]);
369
384
  current[key] = value;
370
385
  current[CLASS] = next[CLASS];
@@ -381,7 +396,7 @@ function set_attributes(
381
396
  var prev_value = current[key];
382
397
 
383
398
  // Skip if value is unchanged, unless it's `undefined` and the element still has the attribute
384
- if (value === prev_value && !(value === undefined && element.hasAttribute(key))) {
399
+ if (value === prev_value && !(value === undefined && has_attribute(element, key))) {
385
400
  continue;
386
401
  }
387
402
 
@@ -395,7 +410,7 @@ function set_attributes(
395
410
  const opts = {};
396
411
  const event_handle_key = '$$' + key;
397
412
  let event_name = key.slice(2);
398
- var is_delegated = can_delegate_event(event_name);
413
+ var is_delegated = current_renderer == null && can_delegate_event(event_name);
399
414
 
400
415
  if (is_capture_event(event_name)) {
401
416
  event_name = event_name.slice(0, -7);
@@ -409,7 +424,7 @@ function set_attributes(
409
424
  // https://github.com/sveltejs/svelte/issues/11903
410
425
  if (value != null) continue;
411
426
 
412
- element.removeEventListener(event_name, current[event_handle_key], opts);
427
+ remove_event_listener(element, event_name, current[event_handle_key], opts);
413
428
  current[event_handle_key] = null;
414
429
  }
415
430
 
@@ -419,10 +434,10 @@ function set_attributes(
419
434
  } else if (value != null) {
420
435
  /**
421
436
  * @this {any}
422
- * @param {Event} evt
437
+ * @param {...any} args
423
438
  */
424
- function handle(evt) {
425
- current[key].call(this, evt);
439
+ function handle(...args) {
440
+ current[key].apply(this, args);
426
441
  }
427
442
 
428
443
  current[event_handle_key] = create_event(event_name, element, handle, opts);
@@ -431,7 +446,16 @@ function set_attributes(
431
446
  // avoid using the setter
432
447
  set_attribute(element, key, value);
433
448
  } else if (key === 'autofocus') {
434
- autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
449
+ if (current_renderer == null) {
450
+ autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
451
+ } else {
452
+ // In custom renderer mode, just set autofocus as a regular attribute
453
+ if (value) {
454
+ set_attribute_op(element, key, value);
455
+ } else {
456
+ remove_attribute(element, key);
457
+ }
458
+ }
435
459
  } else if (!is_custom_element && (key === '__value' || (key === 'value' && value != null))) {
436
460
  // @ts-ignore We're not running this for custom elements because __value is actually
437
461
  // how Lit stores the current value on the element, and messing with that would break things.
@@ -447,8 +471,7 @@ function set_attributes(
447
471
  element.value !== value ||
448
472
  (value === 0 && element.nodeName === PROGRESS_TAG)
449
473
  ) {
450
- // @ts-ignore
451
- element.value = value;
474
+ set_element_value(element, value);
452
475
  }
453
476
  } else if (key === 'selected' && is_option_element) {
454
477
  set_selected(/** @type {HTMLOptionElement} */ (element), value);
@@ -465,26 +488,39 @@ function set_attributes(
465
488
 
466
489
  if (value == null && !is_custom_element && !is_default) {
467
490
  attributes[key] = null;
468
-
469
- if (name === 'value' || name === 'checked') {
491
+ if ((name === 'value' || name === 'checked') && current_renderer == null) {
470
492
  // removing value/checked also removes defaultValue/defaultChecked — preserve
471
493
  let input = /** @type {HTMLInputElement} */ (element);
472
494
  const use_default = prev === undefined;
473
495
  if (name === 'value') {
474
496
  let previous = input.defaultValue;
475
- input.removeAttribute(name);
476
- input.defaultValue = previous;
497
+ remove_attribute(input, name);
498
+ set_element_default_value(input, previous);
477
499
  // @ts-ignore
478
- input.value = input.__value = use_default ? previous : null;
500
+ set_element_value(input, (input.__value = use_default ? previous : null));
479
501
  } else {
480
502
  let previous = input.defaultChecked;
481
- input.removeAttribute(name);
482
- input.defaultChecked = previous;
483
- input.checked = use_default ? previous : false;
503
+ remove_attribute(input, name);
504
+ set_element_default_checked(input, previous);
505
+ set_element_checked(input, use_default ? previous : false);
484
506
  }
485
507
  } else {
486
- element.removeAttribute(key);
508
+ remove_attribute(element, key);
509
+ if (name === 'value') {
510
+ // @ts-ignore
511
+ element.__value = null;
512
+ }
487
513
  }
514
+ } else if (is_default && current_renderer != null) {
515
+ // Route through the renderer-aware abstraction so custom renderers
516
+ // see defaultValue/defaultChecked as proper attributes
517
+ if (name === 'defaultValue') {
518
+ set_element_default_value(element, value);
519
+ } else {
520
+ set_element_default_checked(element, value);
521
+ }
522
+ // remove it from attributes's cache
523
+ if (name in attributes) attributes[name] = UNINITIALIZED;
488
524
  } else if (
489
525
  is_default ||
490
526
  ((is_custom_element || typeof value !== 'string') && setters.has(name))
@@ -534,7 +570,7 @@ export function attribute_effect(
534
570
  /** @type {Record<symbol, Effect>} */
535
571
  var effects = {};
536
572
 
537
- var is_select = element.nodeName === SELECT_TAG;
573
+ var is_select = node_name(element) === SELECT_TAG;
538
574
  var inited = false;
539
575
 
540
576
  managed(() => {
@@ -605,18 +641,21 @@ export function attribute_effect(
605
641
  function get_attributes(element) {
606
642
  return /** @type {Record<string | symbol, unknown>} **/ (
607
643
  /** @type {any} */ (element)[ATTRIBUTES_CACHE] ??= {
608
- [IS_CUSTOM_ELEMENT]: element.nodeName.includes('-'),
609
- [IS_HTML]: element.namespaceURI === NAMESPACE_HTML
644
+ [IS_CUSTOM_ELEMENT]: node_name(element).includes('-'),
645
+ [IS_HTML]: current_renderer == null && element.namespaceURI === NAMESPACE_HTML
610
646
  }
611
647
  );
612
648
  }
613
649
 
614
650
  /** @type {Map<string, Set<string>>} */
615
651
  var setters_cache = new Map();
652
+ var empty_setters = new Set();
616
653
 
617
654
  /** @param {Element} element */
618
655
  function get_setters(element) {
619
- var cache_key = element.getAttribute('is') || element.nodeName;
656
+ // if we have a custom renderer we just skip the check all together
657
+ if (current_renderer) return empty_setters;
658
+ var cache_key = get_attribute(element, 'is') || node_name(element);
620
659
  var setters = setters_cache.get(cache_key);
621
660
  if (setters) return setters;
622
661
  setters_cache.set(cache_key, (setters = new Set()));
@@ -654,9 +693,9 @@ function get_setters(element) {
654
693
  * @param {string} value
655
694
  */
656
695
  function check_src_in_dev_hydration(element, attribute, value) {
657
- if (!DEV) return;
696
+ if (!DEV || current_renderer != null) return;
658
697
  if (attribute === 'srcset' && srcset_url_equal(element, value)) return;
659
- if (src_url_equal(element.getAttribute(attribute) ?? '', value)) return;
698
+ if (src_url_equal(get_attribute(element, attribute) ?? '', value)) return;
660
699
 
661
700
  w.hydration_attribute_changed(
662
701
  attribute,
@@ -671,7 +710,7 @@ function check_src_in_dev_hydration(element, attribute, value) {
671
710
  * @returns {boolean}
672
711
  */
673
712
  function src_url_equal(element_src, url) {
674
- if (element_src === url) return true;
713
+ if (element_src === url || current_renderer != null) return true;
675
714
  return new URL(element_src, document.baseURI).href === new URL(url, document.baseURI).href;
676
715
  }
677
716
 
@@ -686,6 +725,7 @@ function split_srcset(srcset) {
686
725
  * @returns {boolean}
687
726
  */
688
727
  function srcset_url_equal(element, srcset) {
728
+ if (current_renderer != null) return true;
689
729
  var element_urls = split_srcset(element.srcset);
690
730
  var urls = split_srcset(srcset);
691
731
 
@@ -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,
@@ -4,8 +4,12 @@ import { listen_to_event_and_reset_event } from './shared.js';
4
4
  import { is } from '../../../proxy.js';
5
5
  import { is_array } from '../../../../shared/utils.js';
6
6
  import * as w from '../../../warnings.js';
7
- import { current_batch, previous_batch } from '../../../reactivity/batch.js';
8
- import { async_mode_flag } from '../../../../flags/index.js';
7
+ import { current_batch, view_batch } from '../../../reactivity/batch.js';
8
+ import {
9
+ has_attribute,
10
+ remove_attribute,
11
+ set_attribute as set_attribute_op
12
+ } from '../../operations.js';
9
13
 
10
14
  /**
11
15
  * Sets the `selected` attribute on an option so form reset can restore it.
@@ -14,9 +18,13 @@ import { async_mode_flag } from '../../../../flags/index.js';
14
18
  */
15
19
  export function set_selected(option, selected) {
16
20
  if (selected) {
17
- if (!option.hasAttribute('selected')) option.setAttribute('selected', '');
21
+ // The selected option could've changed via user selection, and
22
+ // setting the value without this check would set it back.
23
+ if (!has_attribute(option, 'selected')) {
24
+ set_attribute_op(option, 'selected', '');
25
+ }
18
26
  } else {
19
- option.removeAttribute('selected');
27
+ remove_attribute(option, 'selected');
20
28
  }
21
29
  }
22
30
 
@@ -195,16 +203,12 @@ export function bind_select_value(select, get, set = get) {
195
203
  var value = get();
196
204
 
197
205
  if (select === document.activeElement) {
198
- // In sync mode render effects are executed during tree traversal -> needs current_batch
199
- // In async mode render effects are flushed once batch resolved, at which point current_batch is null -> needs previous_batch
200
- var batch = /** @type {Batch} */ (async_mode_flag ? previous_batch : current_batch);
201
-
202
206
  // Don't update the <select> if it is focused. We can get here if, for example,
203
207
  // an update is deferred because of async work depending on the select:
204
208
  //
205
209
  // <select bind:value={selected}>...</select>
206
210
  // <p>{await find(selected)}</p>
207
- if (batches.has(batch)) {
211
+ if (batches.has(/** @type {Batch} */ (view_batch))) {
208
212
  return;
209
213
  }
210
214
  }
@@ -1,6 +1,14 @@
1
1
  import { to_class } from '../../../shared/attributes.js';
2
+ import { custom_renderers_flag } from '../../../flags/index.js';
3
+ import { current_renderer } from '../../custom-renderer/state.js';
2
4
  import { CLASS_CACHE } from '../../constants.js';
3
5
  import { hydrating } from '../hydration.js';
6
+ import {
7
+ class_list_toggle,
8
+ get_attribute,
9
+ remove_attribute,
10
+ set_attribute
11
+ } from '../operations.js';
4
12
 
5
13
  /**
6
14
  * @param {Element} dom
@@ -17,21 +25,24 @@ export function set_class(dom, is_html, value, hash, prev_classes, next_classes)
17
25
  if (
18
26
  hydrating ||
19
27
  prev !== value ||
20
- prev === undefined // for edge case of `class={undefined}`
28
+ prev === undefined || // for edge case of `class={undefined}`
29
+ // custom renderers only deal in attributes, so rather than toggling individual classes
30
+ // (which would mean editing the `class` attribute), always set the whole thing
31
+ (custom_renderers_flag && current_renderer !== null)
21
32
  ) {
22
33
  var next_class_name = to_class(value, hash, next_classes);
23
34
 
24
- if (!hydrating || next_class_name !== dom.getAttribute('class')) {
35
+ if (!hydrating || next_class_name !== get_attribute(dom, 'class')) {
25
36
  // Removing the attribute when the value is only an empty string causes
26
37
  // performance issues vs simply making the className an empty string. So
27
38
  // we should only remove the class if the value is nullish
28
39
  // and there no hash/directives :
29
40
  if (next_class_name == null) {
30
- dom.removeAttribute('class');
41
+ remove_attribute(dom, 'class');
31
42
  } else if (is_html) {
32
43
  dom.className = next_class_name;
33
44
  } else {
34
- dom.setAttribute('class', next_class_name);
45
+ set_attribute(dom, 'class', next_class_name);
35
46
  }
36
47
  }
37
48
 
@@ -41,7 +52,7 @@ export function set_class(dom, is_html, value, hash, prev_classes, next_classes)
41
52
  var is_present = !!next_classes[key];
42
53
 
43
54
  if (prev_classes == null || is_present !== !!prev_classes[key]) {
44
- dom.classList.toggle(key, is_present);
55
+ class_list_toggle(/** @type {HTMLElement} */ (dom), key, is_present);
45
56
  }
46
57
  }
47
58
  }