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.
- package/compiler/index.js +1 -1
- package/package.json +19 -1
- package/renderer.d.ts +1 -0
- package/src/compiler/errors.js +19 -0
- package/src/compiler/index.js +37 -2
- package/src/compiler/migrate/index.js +2 -1
- package/src/compiler/phases/1-parse/read/options.js +20 -0
- package/src/compiler/phases/2-analyze/index.js +21 -2
- package/src/compiler/phases/2-analyze/visitors/AnimateDirective.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/Attribute.js +6 -2
- package/src/compiler/phases/2-analyze/visitors/BindDirective.js +4 -0
- package/src/compiler/phases/2-analyze/visitors/ExpressionTag.js +2 -1
- package/src/compiler/phases/2-analyze/visitors/HtmlTag.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/OnDirective.js +6 -0
- package/src/compiler/phases/2-analyze/visitors/RegularElement.js +13 -6
- package/src/compiler/phases/2-analyze/visitors/SvelteBody.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteDocument.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteElement.js +5 -1
- package/src/compiler/phases/2-analyze/visitors/SvelteHead.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/SvelteWindow.js +5 -0
- package/src/compiler/phases/2-analyze/visitors/Text.js +3 -1
- package/src/compiler/phases/2-analyze/visitors/TransitionDirective.js +6 -0
- package/src/compiler/phases/2-analyze/visitors/shared/element.js +3 -2
- package/src/compiler/phases/3-transform/client/transform-client.js +68 -1
- package/src/compiler/phases/3-transform/client/transform-template/index.js +4 -3
- package/src/compiler/phases/3-transform/client/transform-template/template.js +1 -1
- package/src/compiler/phases/3-transform/client/utils.js +3 -2
- package/src/compiler/phases/3-transform/client/visitors/RegularElement.js +23 -13
- package/src/compiler/phases/3-transform/client/visitors/RenderTag.js +13 -1
- package/src/compiler/phases/3-transform/client/visitors/SnippetBlock.js +11 -1
- package/src/compiler/phases/3-transform/client/visitors/SvelteBoundary.js +8 -5
- package/src/compiler/phases/3-transform/client/visitors/shared/component.js +17 -8
- package/src/compiler/phases/3-transform/client/visitors/shared/element.js +4 -3
- package/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +7 -1
- package/src/compiler/phases/3-transform/server/transform-server.js +14 -1
- package/src/compiler/phases/3-transform/server/visitors/ExpressionStatement.js +8 -0
- package/src/compiler/phases/3-transform/server/visitors/RegularElement.js +8 -4
- package/src/compiler/print/index.js +45 -57
- package/src/compiler/state.js +12 -0
- package/src/compiler/utils/builders.js +2 -2
- package/src/compiler/validate-options.js +47 -1
- package/src/index-client.js +3 -3
- package/src/internal/client/constants.js +15 -1
- package/src/internal/client/custom-renderer/containers.js +213 -0
- package/src/internal/client/custom-renderer/cross.js +145 -0
- package/src/internal/client/custom-renderer/index.js +28 -0
- package/src/internal/client/custom-renderer/state.js +59 -0
- package/src/internal/client/dev/css.js +3 -1
- package/src/internal/client/dev/debug.js +6 -6
- package/src/internal/client/dev/elements.js +9 -7
- package/src/internal/client/dev/tracing.js +67 -11
- package/src/internal/client/dev/validation.js +2 -1
- package/src/internal/client/dom/blocks/async.js +2 -1
- package/src/internal/client/dom/blocks/await.js +110 -19
- package/src/internal/client/dom/blocks/boundary.js +142 -88
- package/src/internal/client/dom/blocks/branches.js +94 -75
- package/src/internal/client/dom/blocks/css-props.js +31 -3
- package/src/internal/client/dom/blocks/each.js +166 -45
- package/src/internal/client/dom/blocks/html.js +19 -13
- package/src/internal/client/dom/blocks/slot.js +3 -3
- package/src/internal/client/dom/blocks/snippet.js +52 -3
- package/src/internal/client/dom/blocks/svelte-element.js +17 -6
- package/src/internal/client/dom/blocks/svelte-head.js +13 -4
- package/src/internal/client/dom/css.js +4 -4
- package/src/internal/client/dom/elements/attributes.js +91 -51
- package/src/internal/client/dom/elements/bindings/input.js +19 -10
- package/src/internal/client/dom/elements/bindings/select.js +13 -9
- package/src/internal/client/dom/elements/class.js +16 -5
- package/src/internal/client/dom/elements/events.js +153 -21
- package/src/internal/client/dom/elements/misc.js +3 -2
- package/src/internal/client/dom/elements/style.js +17 -6
- package/src/internal/client/dom/hydration.js +6 -6
- package/src/internal/client/dom/operations.js +435 -14
- package/src/internal/client/dom/reconciler.js +2 -2
- package/src/internal/client/dom/template.js +94 -66
- package/src/internal/client/error-handling.js +4 -12
- package/src/internal/client/errors.js +85 -2
- package/src/internal/client/index.js +9 -2
- package/src/internal/client/reactivity/async.js +257 -122
- package/src/internal/client/reactivity/batch.js +1124 -531
- package/src/internal/client/reactivity/deriveds.js +281 -177
- package/src/internal/client/reactivity/effects.js +87 -54
- package/src/internal/client/reactivity/sources.js +30 -124
- package/src/internal/client/reactivity/status.js +1 -1
- package/src/internal/client/render.js +60 -87
- package/src/internal/client/runtime.js +931 -153
- package/src/internal/client/validate.js +2 -2
- package/src/internal/disclose-version.js +1 -1
- package/src/internal/flags/custom-renderer-server.js +10 -0
- package/src/internal/flags/custom-renderer.js +3 -0
- package/src/internal/flags/index.js +6 -0
- package/src/internal/init-operations.js +3 -0
- package/src/internal/shared/errors.js +20 -0
- package/src/legacy/legacy-client.js +6 -2
- package/src/renderer/index-server.js +18 -0
- package/src/renderer/index.js +2 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +245 -25
- package/types/index.d.ts.map +10 -1
- package/src/internal/client/reactivity/utils.js +0 -18
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
BOUNDARY_EFFECT,
|
|
4
4
|
DESTROYED,
|
|
5
5
|
DESTROYING,
|
|
6
|
+
DIRTY,
|
|
6
7
|
EFFECT_PRESERVED,
|
|
7
|
-
EFFECT_TRANSPARENT
|
|
8
|
+
EFFECT_TRANSPARENT,
|
|
9
|
+
MAYBE_DIRTY
|
|
8
10
|
} from '#client/constants';
|
|
9
11
|
import {
|
|
10
12
|
HYDRATION_ERROR,
|
|
@@ -44,8 +46,10 @@ import { Batch, current_batch } from '../../reactivity/batch.js';
|
|
|
44
46
|
import { internal_set, source } from '../../reactivity/sources.js';
|
|
45
47
|
import { tag } from '../../dev/tracing.js';
|
|
46
48
|
import { createSubscriber } from '../../../../reactivity/create-subscriber.js';
|
|
47
|
-
import { create_text } from '../operations.js';
|
|
48
|
-
import {
|
|
49
|
+
import { create_text, create_fragment, append_child, insert_before } from '../operations.js';
|
|
50
|
+
import { set_signal_status } from '../../reactivity/status.js';
|
|
51
|
+
import { push_renderer, pop_renderer } from '../../custom-renderer/state.js';
|
|
52
|
+
import { custom_renderers_flag } from '../../../flags/index.js';
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
55
|
* @typedef {{
|
|
@@ -109,11 +113,20 @@ export class Boundary {
|
|
|
109
113
|
#offscreen_fragment = null;
|
|
110
114
|
|
|
111
115
|
#local_pending_count = 0;
|
|
112
|
-
#pending_count = 0;
|
|
113
116
|
#pending_count_update_queued = false;
|
|
114
117
|
|
|
115
|
-
/**
|
|
116
|
-
|
|
118
|
+
/**
|
|
119
|
+
* User effects created inside this boundary. They will run when the boundary is revealed
|
|
120
|
+
* @type {Effect[]}
|
|
121
|
+
*/
|
|
122
|
+
#effects = [];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Async effects that are currently in flight, grouped by the batch that started them.
|
|
126
|
+
* A speculative fork's work must not hold up the real world's boundary.
|
|
127
|
+
* @type {Map<Batch, Map<Effect, number>>}
|
|
128
|
+
*/
|
|
129
|
+
#pending = new Map();
|
|
117
130
|
|
|
118
131
|
/**
|
|
119
132
|
* A source containing the number of pending async deriveds/expressions.
|
|
@@ -283,42 +296,39 @@ export class Boundary {
|
|
|
283
296
|
queue_micro_task(() => {
|
|
284
297
|
if (this.#is_destroyed()) return;
|
|
285
298
|
|
|
286
|
-
var
|
|
287
|
-
var anchor = create_text();
|
|
288
|
-
var handled = false;
|
|
299
|
+
var previous_renderer = custom_renderers_flag ? push_renderer(this.#effect.r) : null;
|
|
289
300
|
|
|
290
|
-
|
|
301
|
+
try {
|
|
302
|
+
var fragment = (this.#offscreen_fragment = create_fragment());
|
|
303
|
+
var anchor = create_text();
|
|
304
|
+
|
|
305
|
+
append_child(fragment, anchor);
|
|
291
306
|
|
|
292
|
-
|
|
293
|
-
try {
|
|
294
|
-
return branch(() => this.#children(anchor));
|
|
295
|
-
} catch (error) {
|
|
307
|
+
this.#main_effect = this.#run(() => {
|
|
296
308
|
try {
|
|
297
|
-
this
|
|
298
|
-
handled = true;
|
|
309
|
+
return branch(() => this.#children(anchor));
|
|
299
310
|
} catch (error) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
if (this.#main_effect === null) {
|
|
308
|
-
this.#offscreen_fragment = null;
|
|
309
|
-
if (handled) this.#resolve(/** @type {Batch} */ (current_batch));
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
311
|
+
try {
|
|
312
|
+
this.error(error);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
invoke_error_boundary(error, this.#effect.parent);
|
|
315
|
+
}
|
|
312
316
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.#offscreen_fragment = null;
|
|
316
|
-
|
|
317
|
-
pause_effect(/** @type {Effect} */ (this.#pending_effect), () => {
|
|
318
|
-
this.#pending_effect = null;
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
319
|
});
|
|
320
320
|
|
|
321
|
-
this.#
|
|
321
|
+
if (this.#main_effect !== null && this.#pending.size === 0) {
|
|
322
|
+
this.is_pending = false;
|
|
323
|
+
insert_before(this.#anchor, fragment);
|
|
324
|
+
this.#offscreen_fragment = null;
|
|
325
|
+
|
|
326
|
+
pause_effect(/** @type {Effect} */ (this.#pending_effect), () => {
|
|
327
|
+
this.#pending_effect = null;
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
} finally {
|
|
331
|
+
if (custom_renderers_flag) pop_renderer(previous_renderer);
|
|
322
332
|
}
|
|
323
333
|
});
|
|
324
334
|
}
|
|
@@ -326,52 +336,35 @@ export class Boundary {
|
|
|
326
336
|
#render() {
|
|
327
337
|
try {
|
|
328
338
|
this.is_pending = this.has_pending_snippet();
|
|
329
|
-
this.#pending_count = 0;
|
|
330
339
|
this.#local_pending_count = 0;
|
|
331
340
|
|
|
332
341
|
this.#main_effect = branch(() => {
|
|
333
342
|
this.#children(this.#anchor);
|
|
334
343
|
});
|
|
335
344
|
|
|
336
|
-
if (this.#
|
|
337
|
-
|
|
338
|
-
move_effect(this.#main_effect, fragment);
|
|
339
|
-
|
|
340
|
-
const pending = /** @type {(anchor: Node) => void} */ (this.#props.pending);
|
|
341
|
-
this.#pending_effect = branch(() => pending(this.#anchor));
|
|
345
|
+
if (this.#pending.size === 0) {
|
|
346
|
+
this.is_pending = false;
|
|
342
347
|
} else {
|
|
343
|
-
|
|
348
|
+
const pending = this.#props.pending;
|
|
349
|
+
|
|
350
|
+
if (pending) {
|
|
351
|
+
var fragment = (this.#offscreen_fragment = create_fragment());
|
|
352
|
+
move_effect(this.#main_effect, fragment);
|
|
353
|
+
|
|
354
|
+
this.#pending_effect = branch(() => pending(this.#anchor));
|
|
355
|
+
}
|
|
344
356
|
}
|
|
345
357
|
} catch (error) {
|
|
346
358
|
this.error(error);
|
|
347
359
|
}
|
|
348
360
|
}
|
|
349
361
|
|
|
350
|
-
/**
|
|
351
|
-
* @param {Batch} batch
|
|
352
|
-
*/
|
|
353
|
-
#resolve(batch) {
|
|
354
|
-
this.is_pending = false;
|
|
355
|
-
|
|
356
|
-
// any effects that were previously deferred should be transferred
|
|
357
|
-
// to the batch, which will flush in the next microtask
|
|
358
|
-
batch.transfer_reactions(this.#dirty_reactions);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
362
|
/**
|
|
362
363
|
* Defer an effect inside a pending boundary until the boundary resolves
|
|
363
364
|
* @param {Effect} effect
|
|
364
365
|
*/
|
|
365
366
|
defer_effect(effect) {
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Returns `false` if the effect exists inside a boundary whose pending snippet is shown
|
|
371
|
-
* @returns {boolean}
|
|
372
|
-
*/
|
|
373
|
-
is_rendered() {
|
|
374
|
-
return !this.is_pending && (!this.parent || this.parent.is_rendered());
|
|
367
|
+
this.#effects.push(effect);
|
|
375
368
|
}
|
|
376
369
|
|
|
377
370
|
has_pending_snippet() {
|
|
@@ -391,6 +384,8 @@ export class Boundary {
|
|
|
391
384
|
set_active_reaction(this.#effect);
|
|
392
385
|
set_component_context(this.#effect.ctx);
|
|
393
386
|
|
|
387
|
+
var previous_renderer = custom_renderers_flag ? push_renderer(this.#effect.r) : null;
|
|
388
|
+
|
|
394
389
|
try {
|
|
395
390
|
Batch.ensure();
|
|
396
391
|
return fn();
|
|
@@ -398,53 +393,112 @@ export class Boundary {
|
|
|
398
393
|
set_active_effect(previous_effect);
|
|
399
394
|
set_active_reaction(previous_reaction);
|
|
400
395
|
set_component_context(previous_ctx);
|
|
396
|
+
if (custom_renderers_flag) pop_renderer(previous_renderer);
|
|
401
397
|
}
|
|
402
398
|
}
|
|
403
399
|
|
|
404
400
|
/**
|
|
405
|
-
* Updates the pending count associated with the currently visible pending snippet,
|
|
406
|
-
* if any, such that we can replace the snippet with content once work is done
|
|
407
|
-
* @param {1 | -1} d
|
|
408
401
|
* @param {Batch} batch
|
|
409
402
|
*/
|
|
410
|
-
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
403
|
+
is_ready(batch) {
|
|
404
|
+
if (batch.is_fork && this.#pending.size > 0) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
for (const [owner, pending] of this.#pending) {
|
|
409
|
+
if (owner.is_fork) continue;
|
|
410
|
+
|
|
411
|
+
for (const effect of pending.keys()) {
|
|
412
|
+
if (batch.is_blocked_by(effect, this.#main_effect)) {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
414
415
|
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
415
420
|
|
|
416
|
-
|
|
417
|
-
|
|
421
|
+
/**
|
|
422
|
+
* @param {Effect[]} effects
|
|
423
|
+
*/
|
|
424
|
+
reveal(effects) {
|
|
425
|
+
this.is_pending = false;
|
|
426
|
+
|
|
427
|
+
// Add any deferred effects to the batch's effect queue
|
|
428
|
+
for (const effect of this.#effects) {
|
|
429
|
+
set_signal_status(effect, DIRTY);
|
|
430
|
+
effects.push(effect);
|
|
418
431
|
}
|
|
419
432
|
|
|
420
|
-
this.#
|
|
433
|
+
this.#effects.length = 0;
|
|
421
434
|
|
|
422
|
-
if (this.#
|
|
423
|
-
this.#
|
|
435
|
+
if (this.#pending_effect) {
|
|
436
|
+
pause_effect(this.#pending_effect, () => {
|
|
437
|
+
this.#pending_effect = null;
|
|
438
|
+
});
|
|
439
|
+
}
|
|
424
440
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
this.#pending_effect = null;
|
|
428
|
-
});
|
|
429
|
-
}
|
|
441
|
+
if (this.#offscreen_fragment) {
|
|
442
|
+
var previous_renderer = custom_renderers_flag ? push_renderer(this.#effect.r) : null;
|
|
430
443
|
|
|
431
|
-
|
|
432
|
-
this.#anchor
|
|
444
|
+
try {
|
|
445
|
+
insert_before(this.#anchor, this.#offscreen_fragment);
|
|
433
446
|
this.#offscreen_fragment = null;
|
|
447
|
+
} finally {
|
|
448
|
+
if (custom_renderers_flag) pop_renderer(previous_renderer);
|
|
434
449
|
}
|
|
435
450
|
}
|
|
436
451
|
}
|
|
437
452
|
|
|
438
453
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
|
|
442
|
-
|
|
454
|
+
* @param {Effect} effect
|
|
455
|
+
* @param {Batch} batch
|
|
456
|
+
*/
|
|
457
|
+
increment(effect, batch) {
|
|
458
|
+
var pending = this.#pending.get(batch);
|
|
459
|
+
|
|
460
|
+
if (pending === undefined) {
|
|
461
|
+
this.#pending.set(batch, (pending = new Map()));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
var count = pending.get(effect) ?? 0;
|
|
465
|
+
pending.set(effect, count + 1);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @param {Effect} effect
|
|
443
470
|
* @param {Batch} batch
|
|
444
471
|
*/
|
|
445
|
-
|
|
446
|
-
this.#
|
|
472
|
+
decrement(effect, batch) {
|
|
473
|
+
var pending = /** @type {Map<Effect, number>} */ (this.#pending.get(batch));
|
|
474
|
+
var count = /** @type {number} */ (pending.get(effect));
|
|
475
|
+
|
|
476
|
+
if (count === 1) {
|
|
477
|
+
pending.delete(effect);
|
|
478
|
+
|
|
479
|
+
if (pending.size === 0) {
|
|
480
|
+
this.#pending.delete(batch);
|
|
481
|
+
}
|
|
447
482
|
|
|
483
|
+
// The remaining work may belong to speculative forks. Check again in a normal batch,
|
|
484
|
+
// after the result's batch has flushed, so that we reveal committed content and run
|
|
485
|
+
// deferred effects in the same view.
|
|
486
|
+
queue_micro_task(() => {
|
|
487
|
+
if (this.is_pending && !this.#is_destroyed()) {
|
|
488
|
+
Batch.ensure().schedule(this.#effect, MAYBE_DIRTY);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
} else {
|
|
492
|
+
pending.set(effect, count - 1);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Update the source that powers `$effect.pending()` inside this boundary.
|
|
498
|
+
* Do not call from inside the class
|
|
499
|
+
* @param {1 | -1} d
|
|
500
|
+
*/
|
|
501
|
+
update_effect_pending(d) {
|
|
448
502
|
this.#local_pending_count += d;
|
|
449
503
|
|
|
450
504
|
if (!this.#effect_pending || this.#pending_count_update_queued) return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @import { Effect, TemplateNode } from '#client' */
|
|
2
|
+
/** @import { Renderer } from '../../custom-renderer/types.js' */
|
|
2
3
|
/** @import { Batch } from '../../reactivity/batch.js' */
|
|
3
4
|
import { current_batch } from '../../reactivity/batch.js';
|
|
4
5
|
import {
|
|
@@ -9,9 +10,20 @@ import {
|
|
|
9
10
|
resume_effect
|
|
10
11
|
} from '../../reactivity/effects.js';
|
|
11
12
|
import { HMR_ANCHOR } from '../../constants.js';
|
|
13
|
+
import { EFFECT_OFFSCREEN } from '#client/constants';
|
|
12
14
|
import { hydrate_node, hydrating } from '../hydration.js';
|
|
13
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
create_text,
|
|
17
|
+
should_defer_append,
|
|
18
|
+
create_fragment,
|
|
19
|
+
append_child,
|
|
20
|
+
insert_before,
|
|
21
|
+
remove_node,
|
|
22
|
+
get_last_child
|
|
23
|
+
} from '../operations.js';
|
|
14
24
|
import { DEV } from 'esm-env';
|
|
25
|
+
import { push_renderer, current_renderer, pop_renderer } from '../../custom-renderer/state.js';
|
|
26
|
+
import { custom_renderers_flag } from '../../../flags/index.js';
|
|
15
27
|
|
|
16
28
|
/**
|
|
17
29
|
* @typedef {{ effect: Effect, fragment: DocumentFragment }} Branch
|
|
@@ -62,6 +74,14 @@ export class BranchManager {
|
|
|
62
74
|
*/
|
|
63
75
|
#transition = true;
|
|
64
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The renderer that was active when this BranchManager was created.
|
|
79
|
+
* Needed so that #commit can push the correct renderer when doing DOM operations
|
|
80
|
+
* outside of an effect context (e.g. as a batch commit callback).
|
|
81
|
+
* @type {Renderer | null}
|
|
82
|
+
*/
|
|
83
|
+
#renderer = null;
|
|
84
|
+
|
|
65
85
|
/**
|
|
66
86
|
* @param {TemplateNode} anchor
|
|
67
87
|
* @param {boolean} transition
|
|
@@ -69,6 +89,7 @@ export class BranchManager {
|
|
|
69
89
|
constructor(anchor, transition = true) {
|
|
70
90
|
this.anchor = anchor;
|
|
71
91
|
this.#transition = transition;
|
|
92
|
+
this.#renderer = current_renderer;
|
|
72
93
|
}
|
|
73
94
|
|
|
74
95
|
/**
|
|
@@ -78,88 +99,80 @@ export class BranchManager {
|
|
|
78
99
|
// if this batch was made obsolete, bail
|
|
79
100
|
if (!this.#batches.has(batch)) return;
|
|
80
101
|
|
|
81
|
-
var
|
|
102
|
+
var previous_renderer = custom_renderers_flag ? push_renderer(this.#renderer) : null;
|
|
82
103
|
|
|
83
|
-
|
|
104
|
+
try {
|
|
105
|
+
var key = /** @type {Key} */ (this.#batches.get(batch));
|
|
84
106
|
|
|
85
|
-
|
|
86
|
-
// effect is already in the DOM — abort any current outro
|
|
87
|
-
resume_effect(onscreen);
|
|
88
|
-
this.#outroing.delete(key);
|
|
89
|
-
} else {
|
|
90
|
-
// effect is currently offscreen. put it in the DOM
|
|
91
|
-
var offscreen = this.#offscreen.get(key);
|
|
92
|
-
|
|
93
|
-
if (offscreen) {
|
|
94
|
-
// effect could have been outro'ed before through a prior batch — resume if necessary
|
|
95
|
-
resume_effect(offscreen.effect);
|
|
96
|
-
this.#onscreen.set(key, offscreen.effect);
|
|
97
|
-
this.#offscreen.delete(key);
|
|
98
|
-
|
|
99
|
-
if (DEV) {
|
|
100
|
-
// Tell hmr.js about the anchor it should use for updates,
|
|
101
|
-
// since the initial one will be removed
|
|
102
|
-
/** @type {any} */ (offscreen.fragment.lastChild)[HMR_ANCHOR] = this.anchor;
|
|
103
|
-
}
|
|
107
|
+
var onscreen = this.#onscreen.get(key);
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
if (onscreen) {
|
|
110
|
+
// effect is already in the DOM — abort any current outro
|
|
111
|
+
resume_effect(onscreen);
|
|
112
|
+
this.#outroing.delete(key);
|
|
113
|
+
} else {
|
|
114
|
+
// effect is currently offscreen. put it in the DOM
|
|
115
|
+
var offscreen = this.#offscreen.get(key);
|
|
116
|
+
|
|
117
|
+
if (offscreen) {
|
|
118
|
+
// effect could have been outro'ed before through a prior batch — resume if necessary
|
|
119
|
+
resume_effect(offscreen.effect);
|
|
120
|
+
this.#onscreen.set(key, offscreen.effect);
|
|
121
|
+
this.#offscreen.delete(key);
|
|
122
|
+
|
|
123
|
+
if (DEV) {
|
|
124
|
+
// Tell hmr.js about the anchor it should use for updates,
|
|
125
|
+
// since the initial one will be removed
|
|
126
|
+
/** @type {any} */ (get_last_child(offscreen.fragment))[HMR_ANCHOR] = this.anchor;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// remove the anchor...
|
|
130
|
+
remove_node(/** @type {ChildNode} */ (get_last_child(offscreen.fragment)));
|
|
131
|
+
|
|
132
|
+
// ...and append the fragment
|
|
133
|
+
insert_before(this.anchor, offscreen.fragment);
|
|
134
|
+
onscreen = offscreen.effect;
|
|
135
|
+
onscreen.f &= ~EFFECT_OFFSCREEN;
|
|
136
|
+
}
|
|
111
137
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
for (const [b, k] of this.#batches) {
|
|
115
|
-
this.#batches.delete(b);
|
|
116
138
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
139
|
+
// other batches can still commit (in any order), so their selections remain
|
|
140
|
+
this.#discard(batch);
|
|
121
141
|
|
|
122
|
-
|
|
142
|
+
// outro/destroy all onscreen effects...
|
|
143
|
+
for (const [k, effect] of this.#onscreen) {
|
|
144
|
+
// ...except the one that was just committed
|
|
145
|
+
// or those that are already outroing (else the transition is aborted and the effect destroyed right away)
|
|
146
|
+
if (k === key || this.#outroing.has(k)) continue;
|
|
123
147
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// as they will never be committed
|
|
127
|
-
destroy_effect(offscreen.effect);
|
|
128
|
-
this.#offscreen.delete(k);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
148
|
+
const on_destroy = () => {
|
|
149
|
+
const keys = Array.from(this.#batches.values());
|
|
131
150
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (k === key || this.#outroing.has(k)) continue;
|
|
151
|
+
if (keys.includes(k)) {
|
|
152
|
+
// keep the effect offscreen, as another batch will need it
|
|
153
|
+
var fragment = create_fragment();
|
|
154
|
+
move_effect(effect, fragment);
|
|
137
155
|
|
|
138
|
-
|
|
139
|
-
const keys = Array.from(this.#batches.values());
|
|
156
|
+
append_child(fragment, create_text()); // TODO can we avoid this?
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
this.#offscreen.set(k, { effect, fragment });
|
|
159
|
+
} else {
|
|
160
|
+
destroy_effect(effect);
|
|
161
|
+
}
|
|
145
162
|
|
|
146
|
-
|
|
163
|
+
this.#outroing.delete(k);
|
|
164
|
+
this.#onscreen.delete(k);
|
|
165
|
+
};
|
|
147
166
|
|
|
148
|
-
|
|
167
|
+
if (this.#transition || !onscreen) {
|
|
168
|
+
this.#outroing.add(k);
|
|
169
|
+
pause_effect(effect, on_destroy, false);
|
|
149
170
|
} else {
|
|
150
|
-
|
|
171
|
+
on_destroy();
|
|
151
172
|
}
|
|
152
|
-
|
|
153
|
-
this.#outroing.delete(k);
|
|
154
|
-
this.#onscreen.delete(k);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
if (this.#transition || !onscreen) {
|
|
158
|
-
this.#outroing.add(k);
|
|
159
|
-
pause_effect(effect, on_destroy, false);
|
|
160
|
-
} else {
|
|
161
|
-
on_destroy();
|
|
162
173
|
}
|
|
174
|
+
} finally {
|
|
175
|
+
if (custom_renderers_flag) pop_renderer(previous_renderer);
|
|
163
176
|
}
|
|
164
177
|
};
|
|
165
178
|
|
|
@@ -167,7 +180,10 @@ export class BranchManager {
|
|
|
167
180
|
* @param {Batch} batch
|
|
168
181
|
*/
|
|
169
182
|
#discard = (batch) => {
|
|
170
|
-
this.#batches.
|
|
183
|
+
for (const b of this.#batches.keys()) {
|
|
184
|
+
// (batches that were merged into another one don't select anything anymore)
|
|
185
|
+
if (b === batch || !b.linked) this.#batches.delete(b);
|
|
186
|
+
}
|
|
171
187
|
|
|
172
188
|
const keys = Array.from(this.#batches.values());
|
|
173
189
|
|
|
@@ -190,15 +206,18 @@ export class BranchManager {
|
|
|
190
206
|
|
|
191
207
|
if (fn && !this.#onscreen.has(key) && !this.#offscreen.has(key)) {
|
|
192
208
|
if (defer) {
|
|
193
|
-
var fragment =
|
|
209
|
+
var fragment = create_fragment();
|
|
194
210
|
var target = create_text();
|
|
195
211
|
|
|
196
|
-
fragment
|
|
212
|
+
append_child(fragment, target);
|
|
213
|
+
|
|
214
|
+
var effect = branch(() => fn(target));
|
|
215
|
+
|
|
216
|
+
// until it is committed, the branch only exists for the batches that select it
|
|
217
|
+
effect.f |= EFFECT_OFFSCREEN;
|
|
218
|
+
batch.unskip_new_effect(effect);
|
|
197
219
|
|
|
198
|
-
this.#offscreen.set(key, {
|
|
199
|
-
effect: branch(() => fn(target)),
|
|
200
|
-
fragment
|
|
201
|
-
});
|
|
220
|
+
this.#offscreen.set(key, { effect, fragment });
|
|
202
221
|
} else {
|
|
203
222
|
this.#onscreen.set(
|
|
204
223
|
key,
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { render_effect } from '../../reactivity/effects.js';
|
|
2
2
|
import { hydrating, set_hydrate_node } from '../hydration.js';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
get_attribute,
|
|
5
|
+
get_first_child,
|
|
6
|
+
remove_attribute,
|
|
7
|
+
set_css_text,
|
|
8
|
+
style_set_property,
|
|
9
|
+
style_remove_property
|
|
10
|
+
} from '../operations.js';
|
|
11
|
+
import { to_style } from '../../../shared/attributes.js';
|
|
12
|
+
import { custom_renderers_flag } from '../../../flags/index.js';
|
|
13
|
+
import { current_renderer } from '../../custom-renderer/state.js';
|
|
4
14
|
|
|
5
15
|
/**
|
|
6
16
|
* @param {HTMLDivElement | SVGGElement} element
|
|
@@ -12,6 +22,24 @@ export function css_props(element, get_styles) {
|
|
|
12
22
|
set_hydrate_node(get_first_child(element));
|
|
13
23
|
}
|
|
14
24
|
|
|
25
|
+
if (custom_renderers_flag && current_renderer !== null) {
|
|
26
|
+
// custom renderers only deal in attributes, so set the whole `style` attribute: the
|
|
27
|
+
// wrapper's own styles, followed by the custom properties
|
|
28
|
+
var base = get_attribute(element, 'style');
|
|
29
|
+
|
|
30
|
+
render_effect(() => {
|
|
31
|
+
var style = to_style(base, get_styles());
|
|
32
|
+
|
|
33
|
+
if (style === null) {
|
|
34
|
+
remove_attribute(element, 'style');
|
|
35
|
+
} else {
|
|
36
|
+
set_css_text(/** @type {HTMLElement} */ (element), style);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
15
43
|
render_effect(() => {
|
|
16
44
|
var styles = get_styles();
|
|
17
45
|
|
|
@@ -19,9 +47,9 @@ export function css_props(element, get_styles) {
|
|
|
19
47
|
var value = styles[key];
|
|
20
48
|
|
|
21
49
|
if (value == null || value === '') {
|
|
22
|
-
element
|
|
50
|
+
style_remove_property(/** @type {HTMLElement} */ (element), key);
|
|
23
51
|
} else {
|
|
24
|
-
element
|
|
52
|
+
style_set_property(/** @type {HTMLElement} */ (element), key, value);
|
|
25
53
|
}
|
|
26
54
|
}
|
|
27
55
|
});
|