svelte 5.48.5 → 5.49.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/elements.d.ts CHANGED
@@ -2062,7 +2062,7 @@ export interface SvelteHTMLElements {
2062
2062
  | undefined
2063
2063
  | {
2064
2064
  tag?: string;
2065
- shadow?: 'open' | 'none' | undefined;
2065
+ shadow?: 'open' | 'none' | ShadowRootInit | undefined;
2066
2066
  props?:
2067
2067
  | Record<
2068
2068
  string,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "svelte",
3
3
  "description": "Cybernetically enhanced web apps",
4
4
  "license": "MIT",
5
- "version": "5.48.5",
5
+ "version": "5.49.1",
6
6
  "type": "module",
7
7
  "types": "./types/index.d.ts",
8
8
  "engines": {
@@ -139,7 +139,7 @@
139
139
  ],
140
140
  "devDependencies": {
141
141
  "@jridgewell/trace-mapping": "^0.3.25",
142
- "@playwright/test": "^1.46.1",
142
+ "@playwright/test": "^1.58.0",
143
143
  "@rollup/plugin-commonjs": "^28.0.1",
144
144
  "@rollup/plugin-node-resolve": "^15.3.0",
145
145
  "@rollup/plugin-terser": "^0.4.4",
@@ -165,7 +165,7 @@
165
165
  "clsx": "^2.1.1",
166
166
  "devalue": "^5.6.2",
167
167
  "esm-env": "^1.2.1",
168
- "esrap": "^2.2.1",
168
+ "esrap": "^2.2.2",
169
169
  "is-reference": "^3.0.3",
170
170
  "locate-character": "^3.0.0",
171
171
  "magic-string": "^0.30.11",
@@ -1550,12 +1550,12 @@ export function svelte_options_invalid_attribute_value(node, list) {
1550
1550
  }
1551
1551
 
1552
1552
  /**
1553
- * "customElement" must be a string literal defining a valid custom element name or an object of the form { tag?: string; shadow?: "open" | "none"; props?: { [key: string]: { attribute?: string; reflect?: boolean; type: .. } } }
1553
+ * "customElement" must be a string literal defining a valid custom element name or an object of the form { tag?: string; shadow?: "open" | "none" | `ShadowRootInit`; props?: { [key: string]: { attribute?: string; reflect?: boolean; type: .. } } }
1554
1554
  * @param {null | number | NodeLike} node
1555
1555
  * @returns {never}
1556
1556
  */
1557
1557
  export function svelte_options_invalid_customelement(node) {
1558
- e(node, 'svelte_options_invalid_customelement', `"customElement" must be a string literal defining a valid custom element name or an object of the form { tag?: string; shadow?: "open" | "none"; props?: { [key: string]: { attribute?: string; reflect?: boolean; type: .. } } }\nhttps://svelte.dev/e/svelte_options_invalid_customelement`);
1558
+ e(node, 'svelte_options_invalid_customelement', `"customElement" must be a string literal defining a valid custom element name or an object of the form { tag?: string; shadow?: "open" | "none" | \`ShadowRootInit\`; props?: { [key: string]: { attribute?: string; reflect?: boolean; type: .. } } }\nhttps://svelte.dev/e/svelte_options_invalid_customelement`);
1559
1559
  }
1560
1560
 
1561
1561
  /**
@@ -1568,12 +1568,12 @@ export function svelte_options_invalid_customelement_props(node) {
1568
1568
  }
1569
1569
 
1570
1570
  /**
1571
- * "shadow" must be either "open" or "none"
1571
+ * "shadow" must be either "open", "none" or `ShadowRootInit` object.
1572
1572
  * @param {null | number | NodeLike} node
1573
1573
  * @returns {never}
1574
1574
  */
1575
1575
  export function svelte_options_invalid_customelement_shadow(node) {
1576
- e(node, 'svelte_options_invalid_customelement_shadow', `"shadow" must be either "open" or "none"\nhttps://svelte.dev/e/svelte_options_invalid_customelement_shadow`);
1576
+ e(node, 'svelte_options_invalid_customelement_shadow', `"shadow" must be either "open", "none" or \`ShadowRootInit\` object.\nhttps://svelte.dev/e/svelte_options_invalid_customelement_shadow`);
1577
1577
  }
1578
1578
 
1579
1579
  /**
@@ -133,11 +133,13 @@ export default function read_options(node) {
133
133
 
134
134
  const shadow = properties.find(([name]) => name === 'shadow')?.[1];
135
135
  if (shadow) {
136
- const shadowdom = shadow?.value;
137
- if (shadowdom !== 'open' && shadowdom !== 'none') {
138
- e.svelte_options_invalid_customelement_shadow(shadow);
136
+ if (shadow.type === 'Literal' && (shadow.value === 'open' || shadow.value === 'none')) {
137
+ ce.shadow = shadow.value;
138
+ } else if (shadow.type === 'ObjectExpression') {
139
+ ce.shadow = shadow;
140
+ } else {
141
+ e.svelte_options_invalid_customelement_shadow(attribute);
139
142
  }
140
- ce.shadow = shadowdom;
141
143
  }
142
144
 
143
145
  const extend = properties.find(([name]) => name === 'extend')?.[1];
@@ -824,6 +824,10 @@ function has_content(element) {
824
824
  }
825
825
 
826
826
  if (node.type === 'RegularElement' || node.type === 'SvelteElement') {
827
+ if (node.attributes.some((a) => a.type === 'Attribute' && a.name === 'popover')) {
828
+ continue;
829
+ }
830
+
827
831
  if (
828
832
  node.name === 'img' &&
829
833
  node.attributes.some((node) => node.type === 'Attribute' && node.name === 'alt')
@@ -638,7 +638,16 @@ export function client_component(analysis, options) {
638
638
  const accessors_str = b.array(
639
639
  analysis.exports.map(({ name, alias }) => b.literal(alias ?? name))
640
640
  );
641
- const use_shadow_dom = typeof ce === 'boolean' || ce.shadow !== 'none' ? true : false;
641
+
642
+ /** @type {ESTree.ObjectExpression | undefined} */
643
+ let shadow_root_init;
644
+ if (typeof ce === 'boolean' || ce.shadow === 'open' || ce.shadow === undefined) {
645
+ shadow_root_init = b.object([b.init('mode', b.literal('open'))]);
646
+ } else if (ce.shadow === 'none') {
647
+ shadow_root_init = undefined;
648
+ } else {
649
+ shadow_root_init = ce.shadow;
650
+ }
642
651
 
643
652
  const create_ce = b.call(
644
653
  '$.create_custom_element',
@@ -646,7 +655,7 @@ export function client_component(analysis, options) {
646
655
  b.object(props_str),
647
656
  slots_str,
648
657
  accessors_str,
649
- b.literal(use_shadow_dom),
658
+ shadow_root_init,
650
659
  /** @type {any} */ (typeof ce !== 'boolean' ? ce.extend : undefined)
651
660
  );
652
661
 
@@ -162,7 +162,10 @@ function build_assignment(operator, left, right, context) {
162
162
  // will be pushed to. we do this by transforming it to something like
163
163
  // `$.assign_nullish(object, 'items', [])`
164
164
  let should_transform =
165
- dev && path.at(-1) !== 'ExpressionStatement' && is_non_coercive_operator(operator);
165
+ dev &&
166
+ path.at(-1) !== 'ExpressionStatement' &&
167
+ is_non_coercive_operator(operator) &&
168
+ !context.state.scope.evaluate(right).is_primitive;
166
169
 
167
170
  // special case — ignore `onclick={() => (...)}`
168
171
  if (
@@ -70,8 +70,7 @@ export function RegularElement(node, context) {
70
70
  if (optimiser.expressions.length > 0) {
71
71
  context.state.template.push(
72
72
  create_child_block(
73
- b.block([optimiser.apply(), ...state.init, ...build_template(state.template)]),
74
- true
73
+ b.block([optimiser.apply(), ...state.init, ...build_template(state.template)])
75
74
  )
76
75
  );
77
76
  } else {
@@ -133,7 +132,7 @@ export function RegularElement(node, context) {
133
132
 
134
133
  if (optimiser.expressions.length > 0) {
135
134
  context.state.template.push(
136
- create_child_block(b.block([optimiser.apply(), ...state.init, statement]), true)
135
+ create_child_block(b.block([optimiser.apply(), ...state.init, statement]))
137
136
  );
138
137
  } else {
139
138
  context.state.template.push(...state.init, statement);
@@ -186,7 +185,7 @@ export function RegularElement(node, context) {
186
185
 
187
186
  if (optimiser.expressions.length > 0) {
188
187
  context.state.template.push(
189
- create_child_block(b.block([optimiser.apply(), ...state.init, statement]), true)
188
+ create_child_block(b.block([optimiser.apply(), ...state.init, statement]))
190
189
  );
191
190
  } else {
192
191
  context.state.template.push(...state.init, statement);
@@ -236,18 +235,19 @@ export function RegularElement(node, context) {
236
235
  }
237
236
 
238
237
  if (optimiser.is_async()) {
239
- let statement = create_child_block(
240
- b.block([optimiser.apply(), ...state.init, ...build_template(state.template)]),
241
- true
242
- );
238
+ let statements = [...state.init, ...build_template(state.template)];
239
+
240
+ if (optimiser.has_await) {
241
+ statements = [create_child_block(b.block([optimiser.apply(), ...statements]))];
242
+ }
243
243
 
244
244
  const blockers = optimiser.blockers();
245
245
 
246
246
  if (blockers.elements.length > 0) {
247
- statement = create_async_block(b.block([statement]), blockers, false, false);
247
+ statements = [create_async_block(b.block(statements), blockers, false, false)];
248
248
  }
249
249
 
250
- context.state.template.push(statement);
250
+ context.state.template.push(...statements);
251
251
  } else {
252
252
  context.state.init.push(...state.init);
253
253
  context.state.template.push(...state.template);
@@ -79,7 +79,7 @@ export function SvelteElement(node, context) {
79
79
  );
80
80
 
81
81
  if (optimiser.expressions.length > 0) {
82
- statement = create_child_block(b.block([optimiser.apply(), statement]), true);
82
+ statement = create_child_block(b.block([optimiser.apply(), statement]));
83
83
  }
84
84
 
85
85
  statements.push(statement);
@@ -264,11 +264,10 @@ export function build_getter(node, state) {
264
264
  /**
265
265
  * Creates a `$$renderer.child(...)` expression statement
266
266
  * @param {BlockStatement | Expression} body
267
- * @param {boolean} async
268
267
  * @returns {Statement}
269
268
  */
270
- export function create_child_block(body, async) {
271
- return b.stmt(b.call('$$renderer.child', b.arrow([b.id('$$renderer')], body, async)));
269
+ export function create_child_block(body) {
270
+ return b.stmt(b.call('$$renderer.child', b.arrow([b.id('$$renderer')], body, true)));
272
271
  }
273
272
 
274
273
  /**
@@ -228,6 +228,13 @@ class Evaluation {
228
228
  */
229
229
  is_number = true;
230
230
 
231
+ /**
232
+ * True if the value is known to be a primitive
233
+ * @readonly
234
+ * @type {boolean}
235
+ */
236
+ is_primitive = true;
237
+
231
238
  /**
232
239
  * True if the value is known to be a function
233
240
  * @readonly
@@ -577,6 +584,7 @@ class Evaluation {
577
584
 
578
585
  if (value === UNKNOWN) {
579
586
  this.has_unknown = true;
587
+ this.is_primitive = false;
580
588
  }
581
589
  }
582
590
 
@@ -115,57 +115,17 @@ function base_element(node, context) {
115
115
  const is_doctype_node = node.name.toLowerCase() === '!doctype';
116
116
  const is_self_closing =
117
117
  is_void(node.name) || (node.type === 'Component' && node.fragment.nodes.length === 0);
118
- let multiline_content = false;
119
118
 
120
119
  if (is_doctype_node) child_context.write(`>`);
121
120
  else if (is_self_closing) {
122
121
  child_context.write(`${multiline_attributes ? '' : ' '}/>`);
123
122
  } else {
124
123
  child_context.write('>');
125
-
126
- // Process the element's content in a separate context for measurement
127
- const content_context = child_context.new();
128
- const allow_inline_content = child_context.measure() < LINE_BREAK_THRESHOLD;
129
- block(content_context, node.fragment, allow_inline_content);
130
-
131
- // Determine if content should be formatted on multiple lines
132
- multiline_content = content_context.measure() > LINE_BREAK_THRESHOLD;
133
-
134
- if (multiline_content) {
135
- child_context.newline();
136
-
137
- // Only indent if attributes are inline and content itself isn't already multiline
138
- const should_indent = !multiline_attributes && !content_context.multiline;
139
- if (should_indent) {
140
- child_context.indent();
141
- }
142
-
143
- child_context.append(content_context);
144
-
145
- if (should_indent) {
146
- child_context.dedent();
147
- }
148
-
149
- child_context.newline();
150
- } else {
151
- child_context.append(content_context);
152
- }
153
-
124
+ block(child_context, node.fragment, true);
154
125
  child_context.write(`</${node.name}>`);
155
126
  }
156
127
 
157
- const break_line_after = child_context.measure() > LINE_BREAK_THRESHOLD;
158
-
159
- if ((multiline_content || multiline_attributes) && !context.empty()) {
160
- context.newline();
161
- }
162
-
163
128
  context.append(child_context);
164
-
165
- if (is_self_closing) return;
166
- if (multiline_content || multiline_attributes || break_line_after) {
167
- context.newline();
168
- }
169
129
  }
170
130
 
171
131
  /** @type {Visitors<AST.SvelteNode>} */
@@ -412,6 +372,8 @@ const svelte_visitors = {
412
372
  }
413
373
  } else {
414
374
  sequence.push(child_node);
375
+
376
+ if (child_node.type === 'RegularElement') flush();
415
377
  }
416
378
  }
417
379
 
@@ -420,18 +382,20 @@ const svelte_visitors = {
420
382
  let multiline = false;
421
383
  let width = 0;
422
384
 
423
- const child_contexts = items.map((sequence) => {
424
- const child_context = context.new();
385
+ const child_contexts = items
386
+ .filter((x) => x.length > 0)
387
+ .map((sequence) => {
388
+ const child_context = context.new();
425
389
 
426
- for (const node of sequence) {
427
- child_context.visit(node);
428
- multiline ||= child_context.multiline;
429
- }
390
+ for (const node of sequence) {
391
+ child_context.visit(node);
392
+ multiline ||= child_context.multiline;
393
+ }
430
394
 
431
- width += child_context.measure();
395
+ width += child_context.measure();
432
396
 
433
- return child_context;
434
- });
397
+ return child_context;
398
+ });
435
399
 
436
400
  multiline ||= width > LINE_BREAK_THRESHOLD;
437
401
 
@@ -1,3 +1,4 @@
1
+ import { STATE_SYMBOL } from '#client/constants';
1
2
  import { sanitize_location } from '../../../utils.js';
2
3
  import { untrack } from '../runtime.js';
3
4
  import * as w from '../warnings.js';
@@ -10,7 +11,7 @@ import * as w from '../warnings.js';
10
11
  * @param {string} location
11
12
  */
12
13
  function compare(a, b, property, location) {
13
- if (a !== b) {
14
+ if (a !== b && typeof b === 'object' && STATE_SYMBOL in b) {
14
15
  w.assignment_value_stale(property, /** @type {string} */ (sanitize_location(location)));
15
16
  }
16
17
 
@@ -35,18 +35,23 @@ if (typeof HTMLElement === 'function') {
35
35
  $$l_u = new Map();
36
36
  /** @type {any} The managed render effect for reflecting attributes */
37
37
  $$me;
38
+ /** @type {ShadowRoot | null} The ShadowRoot of the custom element */
39
+ $$shadowRoot = null;
38
40
 
39
41
  /**
40
42
  * @param {*} $$componentCtor
41
43
  * @param {*} $$slots
42
- * @param {*} use_shadow_dom
44
+ * @param {ShadowRootInit | undefined} shadow_root_init
43
45
  */
44
- constructor($$componentCtor, $$slots, use_shadow_dom) {
46
+ constructor($$componentCtor, $$slots, shadow_root_init) {
45
47
  super();
46
48
  this.$$ctor = $$componentCtor;
47
49
  this.$$s = $$slots;
48
- if (use_shadow_dom) {
49
- this.attachShadow({ mode: 'open' });
50
+
51
+ if (shadow_root_init) {
52
+ // We need to store the reference to shadow root, because `closed` shadow root cannot be
53
+ // accessed with `this.shadowRoot`.
54
+ this.$$shadowRoot = this.attachShadow(shadow_root_init);
50
55
  }
51
56
  }
52
57
 
@@ -136,7 +141,7 @@ if (typeof HTMLElement === 'function') {
136
141
  }
137
142
  this.$$c = createClassComponent({
138
143
  component: this.$$ctor,
139
- target: this.shadowRoot || this,
144
+ target: this.$$shadowRoot || this,
140
145
  props: {
141
146
  ...this.$$d,
142
147
  $$slots,
@@ -277,7 +282,7 @@ function get_custom_elements_slots(element) {
277
282
  * @param {Record<string, CustomElementPropDefinition>} props_definition The props to observe
278
283
  * @param {string[]} slots The slots to create
279
284
  * @param {string[]} exports Explicitly exported values, other than props
280
- * @param {boolean} use_shadow_dom Whether to use shadow DOM
285
+ * @param {ShadowRootInit | undefined} shadow_root_init Options passed to shadow DOM constructor
281
286
  * @param {(ce: new () => HTMLElement) => new () => HTMLElement} [extend]
282
287
  */
283
288
  export function create_custom_element(
@@ -285,12 +290,12 @@ export function create_custom_element(
285
290
  props_definition,
286
291
  slots,
287
292
  exports,
288
- use_shadow_dom,
293
+ shadow_root_init,
289
294
  extend
290
295
  ) {
291
296
  let Class = class extends SvelteElement {
292
297
  constructor() {
293
- super(Component, slots, use_shadow_dom);
298
+ super(Component, slots, shadow_root_init);
294
299
  this.$$p_d = props_definition;
295
300
  }
296
301
  static get observedAttributes() {
@@ -239,8 +239,6 @@ export function transition(flags, element, get_fn, get_params) {
239
239
  intro?.abort();
240
240
  }
241
241
 
242
- dispatch_event(element, 'introstart');
243
-
244
242
  intro = animate(element, get_options(), outro, 1, () => {
245
243
  dispatch_event(element, 'introend');
246
244
 
@@ -260,8 +258,6 @@ export function transition(flags, element, get_fn, get_params) {
260
258
 
261
259
  element.inert = true;
262
260
 
263
- dispatch_event(element, 'outrostart');
264
-
265
261
  outro = animate(element, get_options(), intro, 0, () => {
266
262
  dispatch_event(element, 'outroend');
267
263
  fn?.();
@@ -345,7 +341,8 @@ function animate(element, options, counterpart, t2, on_finish) {
345
341
 
346
342
  counterpart?.deactivate();
347
343
 
348
- if (!options?.duration) {
344
+ if (!options?.duration && !options?.delay) {
345
+ dispatch_event(element, is_intro ? 'introstart' : 'outrostart');
349
346
  on_finish();
350
347
 
351
348
  return {
@@ -385,6 +382,8 @@ function animate(element, options, counterpart, t2, on_finish) {
385
382
  // remove dummy animation from the stack to prevent conflict with main animation
386
383
  animation.cancel();
387
384
 
385
+ dispatch_event(element, is_intro ? 'introstart' : 'outrostart');
386
+
388
387
  // for bidirectional transitions, we start from the current position,
389
388
  // rather than doing a full intro/outro
390
389
  var t1 = counterpart?.t() ?? 1 - t2;
@@ -122,6 +122,10 @@ export function child(node, is_text) {
122
122
  return text;
123
123
  }
124
124
 
125
+ if (is_text) {
126
+ merge_text_nodes(/** @type {Text} */ (child));
127
+ }
128
+
125
129
  set_hydrate_node(child);
126
130
  return child;
127
131
  }
@@ -142,14 +146,18 @@ export function first_child(node, is_text = false) {
142
146
  return first;
143
147
  }
144
148
 
145
- // if an {expression} is empty during SSR, there might be no
146
- // text node to hydrate we must therefore create one
147
- if (is_text && hydrate_node?.nodeType !== TEXT_NODE) {
148
- var text = create_text();
149
+ if (is_text) {
150
+ // if an {expression} is empty during SSR, there might be no
151
+ // text node to hydrate we must therefore create one
152
+ if (hydrate_node?.nodeType !== TEXT_NODE) {
153
+ var text = create_text();
149
154
 
150
- hydrate_node?.before(text);
151
- set_hydrate_node(text);
152
- return text;
155
+ hydrate_node?.before(text);
156
+ set_hydrate_node(text);
157
+ return text;
158
+ }
159
+
160
+ merge_text_nodes(/** @type {Text} */ (hydrate_node));
153
161
  }
154
162
 
155
163
  return hydrate_node;
@@ -175,20 +183,24 @@ export function sibling(node, count = 1, is_text = false) {
175
183
  return next_sibling;
176
184
  }
177
185
 
178
- // if a sibling {expression} is empty during SSR, there might be no
179
- // text node to hydrate we must therefore create one
180
- if (is_text && next_sibling?.nodeType !== TEXT_NODE) {
181
- var text = create_text();
182
- // If the next sibling is `null` and we're handling text then it's because
183
- // the SSR content was empty for the text, so we need to generate a new text
184
- // node and insert it after the last sibling
185
- if (next_sibling === null) {
186
- last_sibling?.after(text);
187
- } else {
188
- next_sibling.before(text);
186
+ if (is_text) {
187
+ // if a sibling {expression} is empty during SSR, there might be no
188
+ // text node to hydrate we must therefore create one
189
+ if (next_sibling?.nodeType !== TEXT_NODE) {
190
+ var text = create_text();
191
+ // If the next sibling is `null` and we're handling text then it's because
192
+ // the SSR content was empty for the text, so we need to generate a new text
193
+ // node and insert it after the last sibling
194
+ if (next_sibling === null) {
195
+ last_sibling?.after(text);
196
+ } else {
197
+ next_sibling.before(text);
198
+ }
199
+ set_hydrate_node(text);
200
+ return text;
189
201
  }
190
- set_hydrate_node(text);
191
- return text;
202
+
203
+ merge_text_nodes(/** @type {Text} */ (next_sibling));
192
204
  }
193
205
 
194
206
  set_hydrate_node(next_sibling);
@@ -258,3 +270,24 @@ export function set_attribute(element, key, value = '') {
258
270
  }
259
271
  return element.setAttribute(key, value);
260
272
  }
273
+
274
+ /**
275
+ * Browsers split text nodes larger than 65536 bytes when parsing.
276
+ * For hydration to succeed, we need to stitch them back together
277
+ * @param {Text} text
278
+ */
279
+ export function merge_text_nodes(text) {
280
+ if (/** @type {string} */ (text.nodeValue).length < 65536) {
281
+ return;
282
+ }
283
+
284
+ let next = text.nextSibling;
285
+
286
+ while (next !== null && next.nodeType === TEXT_NODE) {
287
+ next.remove();
288
+
289
+ /** @type {string} */ (text.nodeValue) += /** @type {string} */ (next.nodeValue);
290
+
291
+ next = text.nextSibling;
292
+ }
293
+ }
@@ -4,11 +4,13 @@ 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,
7
8
  is_firefox,
8
9
  create_element,
9
10
  create_fragment,
10
11
  create_comment,
11
- set_attribute
12
+ set_attribute,
13
+ merge_text_nodes
12
14
  } from './operations.js';
13
15
  import { create_fragment_from_html } from './reconciler.js';
14
16
  import { active_effect } from '../runtime.js';
@@ -310,6 +312,8 @@ export function text(value = '') {
310
312
  // if an {expression} is empty during SSR, we need to insert an empty text node
311
313
  node.before((node = create_text()));
312
314
  set_hydrate_node(node);
315
+ } else {
316
+ merge_text_nodes(/** @type {Text} */ (node));
313
317
  }
314
318
 
315
319
  assign_nodes(node, node);
@@ -171,6 +171,10 @@ export class Batch {
171
171
  if (this.is_deferred()) {
172
172
  this.#defer_effects(render_effects);
173
173
  this.#defer_effects(effects);
174
+
175
+ for (const e of this.skipped_effects) {
176
+ reset_branch(e);
177
+ }
174
178
  } else {
175
179
  // append/remove branches
176
180
  for (const fn of this.#commit_callbacks) fn();
@@ -881,6 +885,26 @@ export function eager(fn) {
881
885
  return value;
882
886
  }
883
887
 
888
+ /**
889
+ * Mark all the effects inside a skipped branch CLEAN, so that
890
+ * they can be correctly rescheduled later
891
+ * @param {Effect} effect
892
+ */
893
+ function reset_branch(effect) {
894
+ // clean branch = nothing dirty inside, no need to traverse further
895
+ if ((effect.f & BRANCH_EFFECT) !== 0 && (effect.f & CLEAN) !== 0) {
896
+ return;
897
+ }
898
+
899
+ set_signal_status(effect, CLEAN);
900
+
901
+ var e = effect.first;
902
+ while (e !== null) {
903
+ reset_branch(e);
904
+ e = e.next;
905
+ }
906
+ }
907
+
884
908
  /**
885
909
  * Creates a 'fork', in which state changes are evaluated but not applied to the DOM.
886
910
  * This is useful for speculatively loading data (for example) when you suspect that
@@ -972,6 +996,13 @@ export function fork(fn) {
972
996
  await settled;
973
997
  },
974
998
  discard: () => {
999
+ // cause any MAYBE_DIRTY deriveds to update
1000
+ // if they depend on things thath changed
1001
+ // inside the discarded fork
1002
+ for (var source of batch.current.keys()) {
1003
+ source.wv = increment_write_version();
1004
+ }
1005
+
975
1006
  if (!committed && batches.has(batch)) {
976
1007
  batches.delete(batch);
977
1008
  batch.discard();
@@ -43,7 +43,13 @@ import {
43
43
  set_dev_current_component_function,
44
44
  set_dev_stack
45
45
  } from './context.js';
46
- import { Batch, batch_values, flushSync, schedule_effect } from './reactivity/batch.js';
46
+ import {
47
+ Batch,
48
+ batch_values,
49
+ current_batch,
50
+ flushSync,
51
+ schedule_effect
52
+ } from './reactivity/batch.js';
47
53
  import { handle_error } from './error-handling.js';
48
54
  import { UNINITIALIZED } from '../../constants.js';
49
55
  import { captured_signals } from './legacy.js';
@@ -249,10 +255,16 @@ export function update_reaction(reaction) {
249
255
  var result = fn();
250
256
  var deps = reaction.deps;
251
257
 
258
+ // Don't remove reactions during fork;
259
+ // they must remain for when fork is discarded
260
+ var is_fork = current_batch?.is_fork;
261
+
252
262
  if (new_deps !== null) {
253
263
  var i;
254
264
 
255
- remove_reactions(reaction, skipped_deps);
265
+ if (!is_fork) {
266
+ remove_reactions(reaction, skipped_deps);
267
+ }
256
268
 
257
269
  if (deps !== null && skipped_deps > 0) {
258
270
  deps.length = skipped_deps + new_deps.length;
@@ -268,7 +280,7 @@ export function update_reaction(reaction) {
268
280
  (deps[i].reactions ??= []).push(reaction);
269
281
  }
270
282
  }
271
- } else if (deps !== null && skipped_deps < deps.length) {
283
+ } else if (!is_fork && deps !== null && skipped_deps < deps.length) {
272
284
  remove_reactions(reaction, skipped_deps);
273
285
  deps.length = skipped_deps;
274
286
  }