svelte 5.59.1 → 5.59.2

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 (52) hide show
  1. package/LICENSE.md +1 -1
  2. package/compiler/index.js +1 -1
  3. package/package.json +4 -4
  4. package/src/compiler/legacy.js +2 -2
  5. package/src/compiler/phases/1-parse/acorn.js +13 -1
  6. package/src/compiler/phases/1-parse/index.js +50 -7
  7. package/src/compiler/phases/1-parse/read/context.js +1 -1
  8. package/src/compiler/phases/1-parse/read/style.js +9 -8
  9. package/src/compiler/phases/1-parse/state/tag.js +28 -2
  10. package/src/compiler/phases/2-analyze/index.js +2 -1
  11. package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -8
  12. package/src/compiler/phases/3-transform/client/transform-client.js +2 -0
  13. package/src/compiler/phases/3-transform/client/visitors/StaticBlock.js +12 -0
  14. package/src/compiler/phases/3-transform/client/visitors/shared/utils.js +10 -7
  15. package/src/compiler/phases/3-transform/css/index.js +35 -26
  16. package/src/compiler/phases/patterns.js +2 -0
  17. package/src/compiler/phases/scope.js +8 -1
  18. package/src/compiler/print/index.js +18 -9
  19. package/src/compiler/validate-options.js +1 -1
  20. package/src/internal/client/custom-renderer/cross.js +4 -4
  21. package/src/internal/client/dev/elements.js +18 -7
  22. package/src/internal/client/dom/blocks/await.js +5 -0
  23. package/src/internal/client/dom/blocks/boundary.js +2 -2
  24. package/src/internal/client/dom/blocks/branches.js +3 -3
  25. package/src/internal/client/dom/blocks/each.js +16 -13
  26. package/src/internal/client/dom/blocks/html.js +8 -8
  27. package/src/internal/client/dom/blocks/slot.js +8 -13
  28. package/src/internal/client/dom/blocks/snippet.js +6 -7
  29. package/src/internal/client/dom/blocks/svelte-element.js +9 -13
  30. package/src/internal/client/dom/blocks/svelte-head.js +2 -2
  31. package/src/internal/client/dom/css.js +1 -1
  32. package/src/internal/client/dom/elements/attributes.js +15 -2
  33. package/src/internal/client/dom/elements/bindings/select.js +1 -1
  34. package/src/internal/client/dom/elements/transitions.js +88 -83
  35. package/src/internal/client/dom/operations.js +36 -8
  36. package/src/internal/client/dom/template.js +4 -2
  37. package/src/internal/client/proxy.js +19 -11
  38. package/src/internal/client/reactivity/batch.js +58 -18
  39. package/src/internal/client/reactivity/sources.js +39 -6
  40. package/src/internal/client/render.js +2 -2
  41. package/src/internal/client/runtime.js +3 -0
  42. package/src/internal/server/hydratable.js +21 -7
  43. package/src/internal/shared/utils.js +10 -4
  44. package/src/reactivity/create-subscriber.js +1 -1
  45. package/src/reactivity/date.js +3 -2
  46. package/src/reactivity/map.js +26 -11
  47. package/src/reactivity/set.js +23 -10
  48. package/src/reactivity/url-search-params.js +18 -6
  49. package/src/reactivity/url.js +30 -20
  50. package/src/version.js +1 -1
  51. package/types/index.d.ts +24 -16
  52. package/types/index.d.ts.map +1 -1
@@ -46,7 +46,7 @@ import { Batch, current_batch } from '../../reactivity/batch.js';
46
46
  import { internal_set, source } from '../../reactivity/sources.js';
47
47
  import { tag } from '../../dev/tracing.js';
48
48
  import { createSubscriber } from '../../../../reactivity/create-subscriber.js';
49
- import { create_text, create_fragment, append_child, insert_before } from '../operations.js';
49
+ import { create_anchor, create_fragment, append_child, insert_before } from '../operations.js';
50
50
  import { set_signal_status } from '../../reactivity/status.js';
51
51
  import { push_renderer, pop_renderer } from '../../custom-renderer/state.js';
52
52
  import { custom_renderers_flag } from '../../../flags/index.js';
@@ -300,7 +300,7 @@ export class Boundary {
300
300
 
301
301
  try {
302
302
  var fragment = (this.#offscreen_fragment = create_fragment());
303
- var anchor = create_text();
303
+ var anchor = create_anchor();
304
304
 
305
305
  append_child(fragment, anchor);
306
306
 
@@ -13,7 +13,7 @@ import { HMR_ANCHOR } from '../../constants.js';
13
13
  import { EFFECT_OFFSCREEN } from '#client/constants';
14
14
  import { hydrate_node, hydrating } from '../hydration.js';
15
15
  import {
16
- create_text,
16
+ create_anchor,
17
17
  should_defer_append,
18
18
  create_fragment,
19
19
  append_child,
@@ -153,7 +153,7 @@ export class BranchManager {
153
153
  var fragment = create_fragment();
154
154
  move_effect(effect, fragment);
155
155
 
156
- append_child(fragment, create_text()); // TODO can we avoid this?
156
+ append_child(fragment, create_anchor()); // TODO can we avoid this?
157
157
 
158
158
  this.#offscreen.set(k, { effect, fragment });
159
159
  } else {
@@ -207,7 +207,7 @@ export class BranchManager {
207
207
  if (fn && !this.#onscreen.has(key) && !this.#offscreen.has(key)) {
208
208
  if (defer) {
209
209
  var fragment = create_fragment();
210
- var target = create_text();
210
+ var target = create_anchor();
211
211
 
212
212
  append_child(fragment, target);
213
213
 
@@ -1,4 +1,4 @@
1
- /** @import { EachItem, EachOutroGroup, EachState, Effect, EffectNodes, MaybeSource, TemplateNode, TransitionManager } from '#client' */
1
+ /** @import { EachItem, EachOutroGroup, EachState, Effect, EffectNodes, MaybeSource, TemplateNode } from '#client' */
2
2
  /** @import { Batch } from '../../reactivity/batch.js'; */
3
3
  import {
4
4
  EACH_INDEX_REACTIVE,
@@ -20,7 +20,7 @@ import {
20
20
  } from '../hydration.js';
21
21
  import {
22
22
  clear_text_content,
23
- create_text,
23
+ create_anchor,
24
24
  get_first_child,
25
25
  get_next_sibling,
26
26
  should_defer_append,
@@ -73,13 +73,12 @@ export function index(_, i) {
73
73
  * @param {null | Node} controlled_anchor
74
74
  */
75
75
  function pause_effects(state, to_destroy, controlled_anchor) {
76
- /** @type {TransitionManager[]} */
77
- var transitions = [];
76
+ /** @type {Effect[]} */
77
+ var done = [];
78
78
  var length = to_destroy.length;
79
79
 
80
80
  /** @type {EachOutroGroup} */
81
81
  var group;
82
- var remaining = to_destroy.length;
83
82
 
84
83
  for (var i = 0; i < length; i++) {
85
84
  let effect = to_destroy[i];
@@ -102,22 +101,21 @@ function pause_effects(state, to_destroy, controlled_anchor) {
102
101
  }
103
102
  }
104
103
  } else {
105
- remaining -= 1;
104
+ done.push(effect);
106
105
  }
107
106
  },
108
107
  false
109
108
  );
110
109
  }
111
110
 
112
- if (remaining === 0) {
111
+ if (done.length === length) {
113
112
  // If we're in a controlled each block (i.e. the block is the only child of an
114
- // element), and we are removing all items, _and_ there are no out transitions,
113
+ // element), and we are removing all items, _and_ all outros finished synchronously,
115
114
  // we can use the fast path — emptying the element and replacing the anchor.
116
115
  // Skip the fast path when another batch is still pending on this each block:
117
116
  // that batch's keys still reference EachItems in `state.items`, which
118
117
  // `destroy_effects` needs to preserve offscreen (see #18610).
119
- var fast_path =
120
- transitions.length === 0 && controlled_anchor !== null && state.pending.size === 0;
118
+ var fast_path = controlled_anchor !== null && state.pending.size === 0;
121
119
 
122
120
  if (fast_path) {
123
121
  var anchor = /** @type {Element} */ (controlled_anchor);
@@ -133,9 +131,14 @@ function pause_effects(state, to_destroy, controlled_anchor) {
133
131
  } else {
134
132
  group = {
135
133
  pending: new Set(to_destroy),
136
- done: new Set()
134
+ done: new Set(done)
137
135
  };
138
136
 
137
+ // Synchronous outros finished before the group existed.
138
+ for (const effect of done) {
139
+ group.pending.delete(effect);
140
+ }
141
+
139
142
  (state.outrogroups ??= new Set()).add(group);
140
143
  }
141
144
  }
@@ -217,7 +220,7 @@ function get_offscreen_anchor() {
217
220
  var cached = offscreen_anchors.get(current_renderer ?? dom_weak_key);
218
221
  if (cached) return cached;
219
222
 
220
- var offscreen_anchor = create_text();
223
+ var offscreen_anchor = create_anchor();
221
224
 
222
225
  if (current_renderer) {
223
226
  var fragment = create_fragment();
@@ -256,7 +259,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
256
259
 
257
260
  anchor = hydrating
258
261
  ? set_hydrate_node(get_first_child(parent_node))
259
- : /** @type {Text} */ (append_child(parent_node, create_text()));
262
+ : /** @type {Text} */ (append_child(parent_node, create_anchor()));
260
263
  }
261
264
 
262
265
  if (hydrating) {
@@ -13,7 +13,7 @@ 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 { component_context, dev_current_component_function, dev_stack } from '../../context.js';
16
+ import { dev_current_component_function, dev_stack } from '../../context.js';
17
17
  import {
18
18
  create_element,
19
19
  get_first_child,
@@ -26,6 +26,7 @@ import {
26
26
  } from '../operations.js';
27
27
  import { active_effect } from '../../runtime.js';
28
28
  import { COMMENT_NODE, ELEMENT_NODE } from '#client/constants';
29
+ import { set_dev_metadata } from '../../dev/elements.js';
29
30
 
30
31
  /**
31
32
  * @param {string | null} server_hash
@@ -60,13 +61,12 @@ function assign_locations(effect, parent, loc) {
60
61
  var node = effect.nodes.start;
61
62
 
62
63
  while (node !== null) {
63
- if (node_type(node) === ELEMENT_NODE) {
64
- // @ts-expect-error
65
- node.__svelte_meta = {
66
- parent,
67
- loc: { file: loc[0], line: loc[1], column: loc[2] },
68
- component: component_context
69
- };
64
+ if (node.nodeType === ELEMENT_NODE) {
65
+ set_dev_metadata(
66
+ /** @type {Element} */ (node),
67
+ { file: loc[0], line: loc[1], column: loc[2] },
68
+ parent
69
+ );
70
70
  }
71
71
 
72
72
  if (node === effect.nodes.end) break;
@@ -1,7 +1,7 @@
1
1
  import { DEV } from 'esm-env';
2
- import { component_context, dev_stack } from '../../context.js';
2
+ import { set_dev_metadata } from '../../dev/elements.js';
3
3
  import { hydrate_next, hydrating } from '../hydration.js';
4
- import { append_child, create_element, create_text, set_attribute } from '../operations.js';
4
+ import { append_child, create_element, create_anchor, set_attribute } from '../operations.js';
5
5
  import { append } from '../template.js';
6
6
 
7
7
  /**
@@ -26,22 +26,17 @@ export function slot(anchor, $$props, name, slot_props, fallback_fn, location) {
26
26
  if (DEV && location) {
27
27
  // Native slots are created outside the template, so mark their ownership
28
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
- };
29
+ set_dev_metadata(element, {
30
+ file: location[0],
31
+ line: location[1],
32
+ column: location[2]
33
+ });
39
34
  }
40
35
 
41
36
  append(anchor, element);
42
37
 
43
38
  if (fallback_fn !== null) {
44
- const fallback_anchor = create_text();
39
+ const fallback_anchor = create_anchor();
45
40
  append_child(element, fallback_anchor);
46
41
  fallback_fn(fallback_anchor);
47
42
  }
@@ -5,7 +5,6 @@
5
5
  import { EFFECT_TRANSPARENT, ELEMENT_NODE } from '#client/constants';
6
6
  import { block, teardown } from '../../reactivity/effects.js';
7
7
  import {
8
- component_context,
9
8
  dev_current_component_function,
10
9
  dev_stack,
11
10
  set_dev_current_component_function
@@ -19,6 +18,7 @@ import { DEV } from 'esm-env';
19
18
  import { get_first_child, get_next_sibling, insert_before, node_type } from '../operations.js';
20
19
  import { prevent_snippet_stringification } from '../../../shared/validate.js';
21
20
  import { BranchManager } from './branches.js';
21
+ import { set_dev_metadata } from '../../dev/elements.js';
22
22
  import { current_renderer } from '../../custom-renderer/state.js';
23
23
  import { cross, is_crossing } from '../../custom-renderer/cross.js';
24
24
  import { has_own_property } from '../../../shared/utils.js';
@@ -147,12 +147,11 @@ export function createRawSnippet(fn) {
147
147
  if (DEV && dev_stack !== null) {
148
148
  // Raw snippets have no template locations, so use the render callsite.
149
149
  // This also keeps the surrounding template from claiming their root.
150
- // @ts-expect-error
151
- element.__svelte_meta = {
152
- parent: dev_stack,
153
- loc: { file: dev_stack.file, line: dev_stack.line, column: dev_stack.column },
154
- component: component_context
155
- };
150
+ set_dev_metadata(element, {
151
+ file: dev_stack.file,
152
+ line: dev_stack.line,
153
+ column: dev_stack.column
154
+ });
156
155
  }
157
156
 
158
157
  const result = snippet.setup?.(element);
@@ -9,7 +9,7 @@ import {
9
9
  } from '../hydration.js';
10
10
  import {
11
11
  create_element,
12
- create_text,
12
+ create_anchor,
13
13
  get_first_child,
14
14
  append_child,
15
15
  create_comment,
@@ -20,13 +20,14 @@ import {
20
20
  import { block, teardown } from '../../reactivity/effects.js';
21
21
  import { set_should_intro } from '../../render.js';
22
22
  import { active_effect } from '../../runtime.js';
23
- import { component_context, dev_stack } from '../../context.js';
23
+ import { component_context } from '../../context.js';
24
24
  import { DEV } from 'esm-env';
25
25
  import { EFFECT_TRANSPARENT, ELEMENT_NODE } from '#client/constants';
26
26
  import { assign_nodes } from '../template.js';
27
27
  import { is_raw_text_element } from '../../../../utils.js';
28
28
  import { BranchManager } from './branches.js';
29
29
  import { set_animation_effect_override } from '../elements/transitions.js';
30
+ import { set_dev_metadata } from '../../dev/elements.js';
30
31
 
31
32
  /**
32
33
  * @param {Comment | Element} node
@@ -84,16 +85,11 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
84
85
  element = hydrating ? /** @type {Element} */ (element) : create_element(next_tag, ns);
85
86
 
86
87
  if (DEV && location) {
87
- // @ts-expect-error
88
- element.__svelte_meta = {
89
- parent: dev_stack,
90
- loc: {
91
- file: filename,
92
- line: location[0],
93
- column: location[1]
94
- },
95
- component: component_context
96
- };
88
+ set_dev_metadata(element, {
89
+ file: filename,
90
+ line: location[0],
91
+ column: location[1]
92
+ });
97
93
  }
98
94
 
99
95
  assign_nodes(element, element);
@@ -110,7 +106,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
110
106
  // inner open and close methods can pick up the existing nodes correctly
111
107
  var child_anchor = hydrating
112
108
  ? get_first_child(element)
113
- : /** @type {Text} */ (append_child(element, create_text()));
109
+ : /** @type {Text} */ (append_child(element, create_anchor()));
114
110
 
115
111
  if (hydrating) {
116
112
  if (child_anchor === null) {
@@ -2,7 +2,7 @@
2
2
  import { hydrate_node, hydrating, set_hydrate_node, set_hydrating } from '../hydration.js';
3
3
 
4
4
  import {
5
- create_text,
5
+ create_anchor,
6
6
  get_first_child,
7
7
  get_next_sibling,
8
8
  remove_node,
@@ -54,7 +54,7 @@ export function head(hash, render_fn) {
54
54
  }
55
55
 
56
56
  if (!hydrating) {
57
- anchor = /** @type {Comment | Text} */ (append_child(document.head, create_text()));
57
+ anchor = /** @type {Comment | Text} */ (append_child(document.head, create_anchor()));
58
58
  }
59
59
 
60
60
  try {
@@ -19,7 +19,7 @@ export function append_styles(anchor, css) {
19
19
 
20
20
  var target = /** @type {ShadowRoot} */ (root).host
21
21
  ? /** @type {ShadowRoot} */ (root)
22
- : /** @type {Document} */ (root).head ?? /** @type {Document} */ (root.ownerDocument).head;
22
+ : (/** @type {Document} */ (root).head ?? /** @type {Document} */ (root.ownerDocument).head);
23
23
 
24
24
  // Always querying the DOM is roughly the same perf as additionally checking for presence in a map first assuming
25
25
  // that you'll get cache hits half of the time, so we just always query the dom for simplicity and code savings.
@@ -405,6 +405,9 @@ function set_attributes(
405
405
  var prefix = key[0] + key[1]; // this is faster than key.slice(0, 2)
406
406
  if (prefix === '$$') continue;
407
407
 
408
+ // omit event handler attributes regardless of casing, matching SSR
409
+ if (prefix !== 'on' && key.length > 2 && prefix.toLowerCase() === 'on') continue;
410
+
408
411
  if (prefix === 'on') {
409
412
  /** @type {{ capture?: true }} */
410
413
  const opts = {};
@@ -655,10 +658,20 @@ var empty_setters = new Set();
655
658
  function get_setters(element) {
656
659
  // if we have a custom renderer we just skip the check all together
657
660
  if (current_renderer) return empty_setters;
658
- var cache_key = get_attribute(element, 'is') || node_name(element);
661
+ var is = get_attribute(element, 'is');
662
+ var cache_key = is || node_name(element);
659
663
  var setters = setters_cache.get(cache_key);
660
664
  if (setters) return setters;
661
- setters_cache.set(cache_key, (setters = new Set()));
665
+ setters = new Set();
666
+
667
+ // an unregistered custom element can gain setters when it upgrades
668
+ if (
669
+ !customElements ||
670
+ !(is || cache_key.includes('-')) ||
671
+ customElements.get(is || cache_key.toLowerCase())
672
+ ) {
673
+ setters_cache.set(cache_key, setters);
674
+ }
662
675
 
663
676
  var descriptors;
664
677
  var proto = element; // In the case of custom elements there might be setters on the instance
@@ -53,7 +53,7 @@ function apply_default_select_value(select, preserve) {
53
53
  // @ts-expect-error
54
54
  var value = select.__defaultValue;
55
55
  var multiple = select.multiple;
56
- var values = multiple ? value ?? [] : null;
56
+ var values = multiple ? (value ?? []) : null;
57
57
 
58
58
  if (multiple && !is_array(values)) return;
59
59
 
@@ -367,121 +367,126 @@ function animate(element, options, counterpart, t2, on_begin, on_finish) {
367
367
 
368
368
  counterpart?.deactivate();
369
369
 
370
- if (!options?.duration && !options?.delay) {
371
- on_begin();
372
- on_finish();
373
-
374
- return {
375
- abort: noop,
376
- deactivate: noop,
377
- reset: noop,
378
- t: () => t2
379
- };
380
- }
381
-
382
- const { delay = 0, css, tick, easing = linear } = options;
370
+ const { delay = 0, duration = 0, css, tick, easing = linear } = options ?? {};
383
371
 
384
372
  /** @type {globalThis.Animation} */
385
373
  var animation;
386
374
 
387
375
  var get_t = () => 1 - t2;
388
376
 
389
- // wait a microtask before applying the initial styles and creating the dummy animation,
390
- // so that transitions created in the same batch (e.g. on nested elements) all measure
391
- // the DOM first (#18421). this still happens before the next paint, so the element
392
- // won't be rendered without styles applied (#14732)
393
- queue_micro_task(() => {
394
- if (aborted) return;
377
+ function finish() {
378
+ get_t = () => t2;
379
+ tick?.(t2, 1 - t2);
380
+ on_finish();
381
+ }
395
382
 
396
- var keyframes = [];
383
+ function start() {
384
+ on_begin();
397
385
 
398
- if (is_intro && counterpart === undefined) {
399
- if (tick) {
400
- tick(0, 1); // TODO put in nested effect, to avoid interleaved reads/writes?
401
- }
386
+ // for bidirectional transitions, we start from the current position,
387
+ // rather than doing a full intro/outro
388
+ var t1 = counterpart?.t() ?? 1 - t2;
389
+ counterpart?.abort();
390
+
391
+ var delta = t2 - t1;
392
+ var d = duration * Math.abs(delta);
402
393
 
403
- if (css) {
404
- var styles = css_to_keyframe(css(0, 1));
405
- keyframes.push(styles, styles);
394
+ if (d === 0) {
395
+ if (css && !is_intro) {
396
+ var keyframe = css_to_keyframe(css(t2, 1 - t2));
397
+ animation = element.animate([keyframe], { duration: 0, fill: 'forwards' });
406
398
  }
399
+
400
+ finish();
401
+ return;
407
402
  }
408
403
 
409
- // create a dummy animation that lasts as long as the delay (but with whatever devtools
410
- // multiplier is in effect). in the common case that it is `0`, we keep it anyway so that
411
- // the CSS keyframes aren't created until the DOM is updated
412
- //
413
- // fill forwards to prevent the element from rendering without styles applied
414
- // see https://github.com/sveltejs/svelte/issues/14732
415
- animation = element.animate(keyframes, { duration: delay, fill: 'forwards' });
404
+ var keyframes = [];
416
405
 
417
- animation.onfinish = () => {
418
- // remove dummy animation from the stack to prevent conflict with main animation
419
- animation.cancel();
406
+ /**
407
+ * Whether or not the CSS includes `overflow: hidden`, in which case we need to
408
+ * add it as an inline style to work around a Safari <18 bug
409
+ * TODO 6.0 remove this, if possible
410
+ */
411
+ var needs_overflow_hidden = false;
420
412
 
421
- on_begin();
413
+ if (css) {
414
+ var n = Math.ceil(d / (1000 / 60)); // `n` must be an integer, or we risk missing the `t2` value
422
415
 
423
- // for bidirectional transitions, we start from the current position,
424
- // rather than doing a full intro/outro
425
- var t1 = counterpart?.t() ?? 1 - t2;
426
- counterpart?.abort();
416
+ for (var i = 0; i <= n; i += 1) {
417
+ var t = t1 + delta * easing(i / n);
418
+ var styles = css_to_keyframe(css(t, 1 - t));
419
+ keyframes.push(styles);
427
420
 
428
- var delta = t2 - t1;
429
- var duration = /** @type {number} */ (options.duration) * Math.abs(delta);
430
- var keyframes = [];
421
+ needs_overflow_hidden ||= styles.overflow === 'hidden';
422
+ }
423
+ }
431
424
 
432
- if (duration > 0) {
433
- /**
434
- * Whether or not the CSS includes `overflow: hidden`, in which case we need to
435
- * add it as an inline style to work around a Safari <18 bug
436
- * TODO 6.0 remove this, if possible
437
- */
438
- var needs_overflow_hidden = false;
425
+ if (needs_overflow_hidden) {
426
+ /** @type {HTMLElement} */ (element).style.overflow = 'hidden';
427
+ }
439
428
 
440
- if (css) {
441
- var n = Math.ceil(duration / (1000 / 60)); // `n` must be an integer, or we risk missing the `t2` value
429
+ get_t = () => {
430
+ var time = /** @type {number} */ (
431
+ /** @type {globalThis.Animation} */ (animation).currentTime
432
+ );
442
433
 
443
- for (var i = 0; i <= n; i += 1) {
444
- var t = t1 + delta * easing(i / n);
445
- var styles = css_to_keyframe(css(t, 1 - t));
446
- keyframes.push(styles);
434
+ return t1 + delta * easing(time / d);
435
+ };
447
436
 
448
- needs_overflow_hidden ||= styles.overflow === 'hidden';
449
- }
450
- }
437
+ if (tick) {
438
+ loop(() => {
439
+ if (animation.playState !== 'running') return false;
451
440
 
452
- if (needs_overflow_hidden) {
453
- /** @type {HTMLElement} */ (element).style.overflow = 'hidden';
454
- }
441
+ var t = get_t();
442
+ tick(t, 1 - t);
455
443
 
456
- get_t = () => {
457
- var time = /** @type {number} */ (
458
- /** @type {globalThis.Animation} */ (animation).currentTime
459
- );
444
+ return true;
445
+ });
446
+ }
460
447
 
461
- return t1 + delta * easing(time / duration);
462
- };
448
+ animation = element.animate(keyframes, { duration: d, fill: 'forwards' });
449
+ animation.onfinish = finish;
450
+ }
463
451
 
464
- if (tick) {
465
- loop(() => {
466
- if (animation.playState !== 'running') return false;
452
+ if (!duration && !delay) {
453
+ start();
454
+ } else {
455
+ // wait a microtask before applying the initial styles and creating the dummy animation,
456
+ // so that transitions created in the same batch (e.g. on nested elements) all measure
457
+ // the DOM first (#18421). this still happens before the next paint, so the element
458
+ // won't be rendered without styles applied (#14732)
459
+ queue_micro_task(() => {
460
+ if (aborted) return;
467
461
 
468
- var t = get_t();
469
- tick(t, 1 - t);
462
+ var keyframes = [];
470
463
 
471
- return true;
472
- });
464
+ if (is_intro && counterpart === undefined) {
465
+ if (tick) {
466
+ tick(0, 1); // TODO put in nested effect, to avoid interleaved reads/writes?
467
+ }
468
+
469
+ if (css) {
470
+ var styles = css_to_keyframe(css(0, 1));
471
+ keyframes.push(styles, styles);
473
472
  }
474
473
  }
475
474
 
476
- animation = element.animate(keyframes, { duration, fill: 'forwards' });
475
+ // create a dummy animation that lasts as long as the delay (but with whatever devtools
476
+ // multiplier is in effect). in the common case that it is `0`, we keep it anyway so that
477
+ // the CSS keyframes aren't created until the DOM is updated
478
+ //
479
+ // fill forwards to prevent the element from rendering without styles applied
480
+ // see https://github.com/sveltejs/svelte/issues/14732
481
+ animation = element.animate(keyframes, { duration: delay, fill: 'forwards' });
477
482
 
478
483
  animation.onfinish = () => {
479
- get_t = () => t2;
480
- tick?.(t2, 1 - t2);
481
- on_finish();
484
+ // remove dummy animation from the stack to prevent conflict with main animation
485
+ animation.cancel();
486
+ start();
482
487
  };
483
- };
484
- });
488
+ });
489
+ }
485
490
 
486
491
  return {
487
492
  abort: () => {