svelte 5.58.1 → 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/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/RegularElement.js +8 -4
- 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/internal/client/constants.js +7 -0
- 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/elements.js +9 -7
- package/src/internal/client/dev/validation.js +2 -1
- package/src/internal/client/dom/blocks/await.js +3 -2
- package/src/internal/client/dom/blocks/boundary.js +41 -24
- package/src/internal/client/dom/blocks/branches.js +83 -57
- package/src/internal/client/dom/blocks/css-props.js +31 -3
- package/src/internal/client/dom/blocks/each.js +78 -32
- 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 +89 -50
- package/src/internal/client/dom/elements/bindings/select.js +11 -2
- package/src/internal/client/dom/elements/class.js +16 -5
- package/src/internal/client/dom/elements/events.js +126 -19
- 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 +433 -11
- package/src/internal/client/dom/reconciler.js +2 -2
- package/src/internal/client/dom/template.js +94 -66
- package/src/internal/client/errors.js +67 -0
- package/src/internal/client/index.js +9 -1
- package/src/internal/client/reactivity/async.js +10 -0
- package/src/internal/client/reactivity/batch.js +22 -1
- package/src/internal/client/reactivity/effects.js +44 -27
- package/src/internal/client/render.js +50 -88
- package/src/internal/client/runtime.js +6 -1
- 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 +244 -24
- package/types/index.d.ts.map +10 -1
|
@@ -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 {
|
|
@@ -11,8 +12,18 @@ import {
|
|
|
11
12
|
import { HMR_ANCHOR } from '../../constants.js';
|
|
12
13
|
import { EFFECT_OFFSCREEN } from '#client/constants';
|
|
13
14
|
import { hydrate_node, hydrating } from '../hydration.js';
|
|
14
|
-
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';
|
|
15
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';
|
|
16
27
|
|
|
17
28
|
/**
|
|
18
29
|
* @typedef {{ effect: Effect, fragment: DocumentFragment }} Branch
|
|
@@ -63,6 +74,14 @@ export class BranchManager {
|
|
|
63
74
|
*/
|
|
64
75
|
#transition = true;
|
|
65
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
|
+
|
|
66
85
|
/**
|
|
67
86
|
* @param {TemplateNode} anchor
|
|
68
87
|
* @param {boolean} transition
|
|
@@ -70,6 +89,7 @@ export class BranchManager {
|
|
|
70
89
|
constructor(anchor, transition = true) {
|
|
71
90
|
this.anchor = anchor;
|
|
72
91
|
this.#transition = transition;
|
|
92
|
+
this.#renderer = current_renderer;
|
|
73
93
|
}
|
|
74
94
|
|
|
75
95
|
/**
|
|
@@ -79,74 +99,80 @@ export class BranchManager {
|
|
|
79
99
|
// if this batch was made obsolete, bail
|
|
80
100
|
if (!this.#batches.has(batch)) return;
|
|
81
101
|
|
|
82
|
-
var
|
|
102
|
+
var previous_renderer = custom_renderers_flag ? push_renderer(this.#renderer) : null;
|
|
83
103
|
|
|
84
|
-
|
|
104
|
+
try {
|
|
105
|
+
var key = /** @type {Key} */ (this.#batches.get(batch));
|
|
85
106
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
var onscreen = this.#onscreen.get(key);
|
|
108
|
+
|
|
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;
|
|
104
136
|
}
|
|
137
|
+
}
|
|
105
138
|
|
|
106
|
-
|
|
107
|
-
|
|
139
|
+
// other batches can still commit (in any order), so their selections remain
|
|
140
|
+
this.#discard(batch);
|
|
108
141
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
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;
|
|
115
147
|
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
const on_destroy = () => {
|
|
149
|
+
const keys = Array.from(this.#batches.values());
|
|
118
150
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
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);
|
|
124
155
|
|
|
125
|
-
|
|
126
|
-
const keys = Array.from(this.#batches.values());
|
|
156
|
+
append_child(fragment, create_text()); // TODO can we avoid this?
|
|
127
157
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
158
|
+
this.#offscreen.set(k, { effect, fragment });
|
|
159
|
+
} else {
|
|
160
|
+
destroy_effect(effect);
|
|
161
|
+
}
|
|
132
162
|
|
|
133
|
-
|
|
163
|
+
this.#outroing.delete(k);
|
|
164
|
+
this.#onscreen.delete(k);
|
|
165
|
+
};
|
|
134
166
|
|
|
135
|
-
|
|
167
|
+
if (this.#transition || !onscreen) {
|
|
168
|
+
this.#outroing.add(k);
|
|
169
|
+
pause_effect(effect, on_destroy, false);
|
|
136
170
|
} else {
|
|
137
|
-
|
|
171
|
+
on_destroy();
|
|
138
172
|
}
|
|
139
|
-
|
|
140
|
-
this.#outroing.delete(k);
|
|
141
|
-
this.#onscreen.delete(k);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (this.#transition || !onscreen) {
|
|
145
|
-
this.#outroing.add(k);
|
|
146
|
-
pause_effect(effect, on_destroy, false);
|
|
147
|
-
} else {
|
|
148
|
-
on_destroy();
|
|
149
173
|
}
|
|
174
|
+
} finally {
|
|
175
|
+
if (custom_renderers_flag) pop_renderer(previous_renderer);
|
|
150
176
|
}
|
|
151
177
|
};
|
|
152
178
|
|
|
@@ -180,10 +206,10 @@ export class BranchManager {
|
|
|
180
206
|
|
|
181
207
|
if (fn && !this.#onscreen.has(key) && !this.#offscreen.has(key)) {
|
|
182
208
|
if (defer) {
|
|
183
|
-
var fragment =
|
|
209
|
+
var fragment = create_fragment();
|
|
184
210
|
var target = create_text();
|
|
185
211
|
|
|
186
|
-
fragment
|
|
212
|
+
append_child(fragment, target);
|
|
187
213
|
|
|
188
214
|
var effect = branch(() => fn(target));
|
|
189
215
|
|
|
@@ -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
|
});
|
|
@@ -23,7 +23,13 @@ import {
|
|
|
23
23
|
create_text,
|
|
24
24
|
get_first_child,
|
|
25
25
|
get_next_sibling,
|
|
26
|
-
should_defer_append
|
|
26
|
+
should_defer_append,
|
|
27
|
+
get_parent_node,
|
|
28
|
+
append_child,
|
|
29
|
+
create_fragment,
|
|
30
|
+
insert_before,
|
|
31
|
+
node_type,
|
|
32
|
+
get_node_value
|
|
27
33
|
} from '../operations.js';
|
|
28
34
|
import {
|
|
29
35
|
block,
|
|
@@ -44,6 +50,9 @@ import { current_batch } from '../../reactivity/batch.js';
|
|
|
44
50
|
import * as e from '../../errors.js';
|
|
45
51
|
import { tag } from '../../dev/tracing.js';
|
|
46
52
|
|
|
53
|
+
import { push_renderer, current_renderer, pop_renderer } from '../../custom-renderer/state.js';
|
|
54
|
+
import { custom_renderers_flag } from '../../../flags/index.js';
|
|
55
|
+
|
|
47
56
|
// When making substantive changes to this file, validate them with the each block stress test:
|
|
48
57
|
// https://svelte.dev/playground/1972b2cf46564476ad8c8c6405b23b7b
|
|
49
58
|
// This test also exists in this repo, as `packages/svelte/tests/manual/each-stress-test`
|
|
@@ -112,10 +121,10 @@ function pause_effects(state, to_destroy, controlled_anchor) {
|
|
|
112
121
|
|
|
113
122
|
if (fast_path) {
|
|
114
123
|
var anchor = /** @type {Element} */ (controlled_anchor);
|
|
115
|
-
var parent_node = /** @type {Element} */ (anchor
|
|
124
|
+
var parent_node = /** @type {Element} */ (get_parent_node(anchor));
|
|
116
125
|
|
|
117
126
|
clear_text_content(parent_node);
|
|
118
|
-
parent_node
|
|
127
|
+
append_child(parent_node, anchor);
|
|
119
128
|
|
|
120
129
|
state.items.clear();
|
|
121
130
|
}
|
|
@@ -160,7 +169,7 @@ function destroy_effects(state, to_destroy, remove_dom = true) {
|
|
|
160
169
|
if (preserved_effects?.has(e)) {
|
|
161
170
|
e.f |= EFFECT_OFFSCREEN;
|
|
162
171
|
|
|
163
|
-
const fragment =
|
|
172
|
+
const fragment = create_fragment();
|
|
164
173
|
move_effect(e, fragment);
|
|
165
174
|
|
|
166
175
|
// `reconcile` expects offscreen items to come after all onscreen items
|
|
@@ -190,8 +199,34 @@ function is_outroing(state, effect) {
|
|
|
190
199
|
return false;
|
|
191
200
|
}
|
|
192
201
|
|
|
193
|
-
|
|
194
|
-
|
|
202
|
+
// we need to handle the case of multiple renderers so we need to use a WeakMap of offscreen anchors rather than a single variable.
|
|
203
|
+
// we also need the dom_weak_key since `null` is not a viable WeakKey
|
|
204
|
+
/** @type {WeakMap<WeakKey, TemplateNode>} */
|
|
205
|
+
var offscreen_anchors = new WeakMap();
|
|
206
|
+
var dom_weak_key = {};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Returns an anchor node suitable for offscreen rendering.
|
|
210
|
+
* When a custom renderer is active, the anchor must have a parent
|
|
211
|
+
* (so that `getParent()` works), so we place the text node inside
|
|
212
|
+
* a fragment. The result is cached just like the non-renderer path.
|
|
213
|
+
* @returns {TemplateNode}
|
|
214
|
+
*/
|
|
215
|
+
function get_offscreen_anchor() {
|
|
216
|
+
// not doing it inline to please typescript
|
|
217
|
+
var cached = offscreen_anchors.get(current_renderer ?? dom_weak_key);
|
|
218
|
+
if (cached) return cached;
|
|
219
|
+
|
|
220
|
+
var offscreen_anchor = create_text();
|
|
221
|
+
|
|
222
|
+
if (current_renderer) {
|
|
223
|
+
var fragment = create_fragment();
|
|
224
|
+
append_child(fragment, offscreen_anchor);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
offscreen_anchors.set(current_renderer ?? dom_weak_key, offscreen_anchor);
|
|
228
|
+
return offscreen_anchor;
|
|
229
|
+
}
|
|
195
230
|
|
|
196
231
|
/**
|
|
197
232
|
* @template V
|
|
@@ -211,12 +246,17 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
211
246
|
|
|
212
247
|
var is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
|
|
213
248
|
|
|
249
|
+
// Capture the renderer that was active when this each block was created.
|
|
250
|
+
// Needed so that the commit callback can push the correct renderer when doing
|
|
251
|
+
// DOM operations outside of an effect context (e.g. as a batch commit callback).
|
|
252
|
+
var renderer = current_renderer;
|
|
253
|
+
|
|
214
254
|
if (is_controlled) {
|
|
215
255
|
var parent_node = /** @type {Element} */ (node);
|
|
216
256
|
|
|
217
257
|
anchor = hydrating
|
|
218
258
|
? set_hydrate_node(get_first_child(parent_node))
|
|
219
|
-
: parent_node
|
|
259
|
+
: /** @type {Text} */ (append_child(parent_node, create_text()));
|
|
220
260
|
}
|
|
221
261
|
|
|
222
262
|
if (hydrating) {
|
|
@@ -254,32 +294,38 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
254
294
|
return;
|
|
255
295
|
}
|
|
256
296
|
|
|
257
|
-
|
|
297
|
+
var previous_renderer = custom_renderers_flag ? push_renderer(renderer) : null;
|
|
258
298
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
// as the committing batch sees it rather than using the most recent block run's result
|
|
262
|
-
var array = get(each_array);
|
|
299
|
+
try {
|
|
300
|
+
state.pending.delete(batch);
|
|
263
301
|
|
|
264
|
-
|
|
265
|
-
|
|
302
|
+
// The effect doesn't necessarily re-run in a batch right before that batch commits
|
|
303
|
+
// (its view of the collection may not have changed), so we read the collection
|
|
304
|
+
// as the committing batch sees it rather than using the most recent block run's result
|
|
305
|
+
var array = get(each_array);
|
|
266
306
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
307
|
+
state.fallback = fallback;
|
|
308
|
+
reconcile(state, array, anchor, flags, get_key);
|
|
309
|
+
|
|
310
|
+
if (fallback !== null) {
|
|
311
|
+
if (array.length === 0) {
|
|
312
|
+
if ((fallback.f & EFFECT_OFFSCREEN) === 0) {
|
|
313
|
+
resume_effect(fallback);
|
|
314
|
+
} else {
|
|
315
|
+
fallback.f ^= EFFECT_OFFSCREEN;
|
|
316
|
+
move(fallback, null, anchor);
|
|
317
|
+
}
|
|
271
318
|
} else {
|
|
272
|
-
fallback
|
|
273
|
-
|
|
319
|
+
pause_effect(fallback, () => {
|
|
320
|
+
// TODO only null out if no pending batch needs it,
|
|
321
|
+
// otherwise re-add `fallback.fragment` and move the
|
|
322
|
+
// effect into it
|
|
323
|
+
fallback = null;
|
|
324
|
+
});
|
|
274
325
|
}
|
|
275
|
-
} else {
|
|
276
|
-
pause_effect(fallback, () => {
|
|
277
|
-
// TODO only null out if no pending batch needs it,
|
|
278
|
-
// otherwise re-add `fallback.fragment` and move the
|
|
279
|
-
// effect into it
|
|
280
|
-
fallback = null;
|
|
281
|
-
});
|
|
282
326
|
}
|
|
327
|
+
} finally {
|
|
328
|
+
if (custom_renderers_flag) pop_renderer(previous_renderer);
|
|
283
329
|
}
|
|
284
330
|
|
|
285
331
|
destroy_unselected();
|
|
@@ -355,8 +401,8 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
355
401
|
for (var index = 0; index < length; index += 1) {
|
|
356
402
|
if (
|
|
357
403
|
hydrating &&
|
|
358
|
-
hydrate_node
|
|
359
|
-
|
|
404
|
+
node_type(hydrate_node) === COMMENT_NODE &&
|
|
405
|
+
get_node_value(hydrate_node) === HYDRATION_END
|
|
360
406
|
) {
|
|
361
407
|
// The server rendered fewer items than expected,
|
|
362
408
|
// so break out and continue appending non-hydrated items
|
|
@@ -389,7 +435,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
389
435
|
} else {
|
|
390
436
|
item = create_item(
|
|
391
437
|
items,
|
|
392
|
-
first_run ? anchor : (
|
|
438
|
+
first_run ? anchor : get_offscreen_anchor(),
|
|
393
439
|
value,
|
|
394
440
|
key,
|
|
395
441
|
index,
|
|
@@ -414,7 +460,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
|
|
|
414
460
|
if (first_run) {
|
|
415
461
|
fallback = branch(() => fallback_fn(anchor));
|
|
416
462
|
} else {
|
|
417
|
-
fallback = branch(() => fallback_fn((
|
|
463
|
+
fallback = branch(() => fallback_fn(get_offscreen_anchor()));
|
|
418
464
|
// until it is committed, the fallback only exists for the batches that select it
|
|
419
465
|
fallback.f |= EFFECT_OFFSCREEN;
|
|
420
466
|
if (defer) batch.unskip_new_effect(fallback);
|
|
@@ -796,7 +842,7 @@ function move(effect, next, anchor) {
|
|
|
796
842
|
|
|
797
843
|
while (node !== null) {
|
|
798
844
|
var next_node = /** @type {TemplateNode} */ (get_next_sibling(node));
|
|
799
|
-
dest
|
|
845
|
+
insert_before(dest, node);
|
|
800
846
|
|
|
801
847
|
if (node === end) {
|
|
802
848
|
return;
|
|
@@ -14,7 +14,16 @@ import * as w from '../../warnings.js';
|
|
|
14
14
|
import { hash, sanitize_location } from '../../../../utils.js';
|
|
15
15
|
import { DEV } from 'esm-env';
|
|
16
16
|
import { component_context, dev_current_component_function, dev_stack } from '../../context.js';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
create_element,
|
|
19
|
+
get_first_child,
|
|
20
|
+
get_next_sibling,
|
|
21
|
+
get_last_child,
|
|
22
|
+
set_inner_html,
|
|
23
|
+
insert_before,
|
|
24
|
+
node_type,
|
|
25
|
+
get_node_value
|
|
26
|
+
} from '../operations.js';
|
|
18
27
|
import { active_effect } from '../../runtime.js';
|
|
19
28
|
import { COMMENT_NODE, ELEMENT_NODE } from '#client/constants';
|
|
20
29
|
|
|
@@ -51,7 +60,7 @@ function assign_locations(effect, parent, loc) {
|
|
|
51
60
|
var node = effect.nodes.start;
|
|
52
61
|
|
|
53
62
|
while (node !== null) {
|
|
54
|
-
if (node
|
|
63
|
+
if (node_type(node) === ELEMENT_NODE) {
|
|
55
64
|
// @ts-expect-error
|
|
56
65
|
node.__svelte_meta = {
|
|
57
66
|
parent,
|
|
@@ -110,12 +119,12 @@ export function html(
|
|
|
110
119
|
// When @html is the only child, use innerHTML directly.
|
|
111
120
|
// This also handles contenteditable, where the user may delete the anchor comment.
|
|
112
121
|
effect.nodes = null;
|
|
113
|
-
parent_node
|
|
122
|
+
set_inner_html(parent_node, /** @type {string} */ (value));
|
|
114
123
|
|
|
115
124
|
if (value !== '') {
|
|
116
125
|
assign_nodes(
|
|
117
126
|
/** @type {TemplateNode} */ (get_first_child(parent_node)),
|
|
118
|
-
/** @type {TemplateNode} */ (parent_node
|
|
127
|
+
/** @type {TemplateNode} */ (get_last_child(parent_node))
|
|
119
128
|
);
|
|
120
129
|
|
|
121
130
|
if (DEV && location) assign_locations(effect, parent, location);
|
|
@@ -134,16 +143,13 @@ export function html(
|
|
|
134
143
|
if (hydrating) {
|
|
135
144
|
// We're deliberately not trying to repair mismatches between server and client,
|
|
136
145
|
// as it's costly and error-prone (and it's an edge case to have a mismatch anyway)
|
|
137
|
-
var hash =
|
|
146
|
+
var hash = get_node_value(hydrate_node);
|
|
138
147
|
|
|
139
148
|
/** @type {TemplateNode | null} */
|
|
140
149
|
var next = hydrate_next();
|
|
141
150
|
var last = next;
|
|
142
151
|
|
|
143
|
-
while (
|
|
144
|
-
next !== null &&
|
|
145
|
-
(next.nodeType !== COMMENT_NODE || /** @type {Comment} */ (next).data !== '')
|
|
146
|
-
) {
|
|
152
|
+
while (next !== null && (node_type(next) !== COMMENT_NODE || get_node_value(next) !== '')) {
|
|
147
153
|
last = next;
|
|
148
154
|
next = get_next_sibling(next);
|
|
149
155
|
}
|
|
@@ -171,24 +177,24 @@ export function html(
|
|
|
171
177
|
var wrapper = /** @type {HTMLTemplateElement | SVGElement | MathMLElement} */ (
|
|
172
178
|
create_element(svg ? 'svg' : mathml ? 'math' : 'template', ns)
|
|
173
179
|
);
|
|
174
|
-
wrapper
|
|
180
|
+
set_inner_html(wrapper, /** @type {any} */ (value));
|
|
175
181
|
|
|
176
182
|
/** @type {DocumentFragment | Element} */
|
|
177
183
|
var node = svg || mathml ? wrapper : /** @type {HTMLTemplateElement} */ (wrapper).content;
|
|
178
184
|
|
|
179
185
|
assign_nodes(
|
|
180
186
|
/** @type {TemplateNode} */ (get_first_child(node)),
|
|
181
|
-
/** @type {TemplateNode} */ (node
|
|
187
|
+
/** @type {TemplateNode} */ (get_last_child(node))
|
|
182
188
|
);
|
|
183
189
|
|
|
184
190
|
if (DEV && location) assign_locations(effect, parent, location);
|
|
185
191
|
|
|
186
192
|
if (svg || mathml) {
|
|
187
193
|
while (get_first_child(node)) {
|
|
188
|
-
anchor
|
|
194
|
+
insert_before(anchor, /** @type {TemplateNode} */ (get_first_child(node)));
|
|
189
195
|
}
|
|
190
196
|
} else {
|
|
191
|
-
anchor
|
|
197
|
+
insert_before(anchor, node);
|
|
192
198
|
}
|
|
193
199
|
});
|
|
194
200
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEV } from 'esm-env';
|
|
2
2
|
import { component_context, dev_stack } from '../../context.js';
|
|
3
3
|
import { hydrate_next, hydrating } from '../hydration.js';
|
|
4
|
-
import { create_element, create_text } from '../operations.js';
|
|
4
|
+
import { append_child, create_element, create_text, set_attribute } from '../operations.js';
|
|
5
5
|
import { append } from '../template.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -21,7 +21,7 @@ export function slot(anchor, $$props, name, slot_props, fallback_fn, location) {
|
|
|
21
21
|
// Use the stored reference because the shadow root may be closed.
|
|
22
22
|
if ($$props.$$host?.$$shadowRoot) {
|
|
23
23
|
const element = create_element('slot');
|
|
24
|
-
if (name !== 'default') element
|
|
24
|
+
if (name !== 'default') set_attribute(element, 'name', name);
|
|
25
25
|
|
|
26
26
|
if (DEV && location) {
|
|
27
27
|
// Native slots are created outside the template, so mark their ownership
|
|
@@ -42,7 +42,7 @@ export function slot(anchor, $$props, name, slot_props, fallback_fn, location) {
|
|
|
42
42
|
|
|
43
43
|
if (fallback_fn !== null) {
|
|
44
44
|
const fallback_anchor = create_text();
|
|
45
|
-
element
|
|
45
|
+
append_child(element, fallback_anchor);
|
|
46
46
|
fallback_fn(fallback_anchor);
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @import { Renderer } from '../../custom-renderer/types.js' */
|
|
1
2
|
/** @import { Snippet } from 'svelte' */
|
|
2
3
|
/** @import { TemplateNode } from '#client' */
|
|
3
4
|
/** @import { Getters } from '#shared' */
|
|
@@ -15,9 +16,12 @@ import { assign_nodes } from '../template.js';
|
|
|
15
16
|
import * as w from '../../warnings.js';
|
|
16
17
|
import * as e from '../../errors.js';
|
|
17
18
|
import { DEV } from 'esm-env';
|
|
18
|
-
import { get_first_child, get_next_sibling } from '../operations.js';
|
|
19
|
+
import { get_first_child, get_next_sibling, insert_before, node_type } from '../operations.js';
|
|
19
20
|
import { prevent_snippet_stringification } from '../../../shared/validate.js';
|
|
20
21
|
import { BranchManager } from './branches.js';
|
|
22
|
+
import { current_renderer } from '../../custom-renderer/state.js';
|
|
23
|
+
import { cross, is_crossing } from '../../custom-renderer/cross.js';
|
|
24
|
+
import { has_own_property } from '../../../shared/utils.js';
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* @template {(node: TemplateNode, ...args: any[]) => void} SnippetFn
|
|
@@ -63,6 +67,48 @@ export function wrap_snippet(component, fn) {
|
|
|
63
67
|
return snippet;
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Wraps a snippet function so that it remembers which renderer it was compiled for
|
|
72
|
+
* (`null` for DOM). If it is rendered by a different renderer, the snippet content
|
|
73
|
+
* is rendered across a renderer boundary (see `cross`).
|
|
74
|
+
* @template {(...args: any[]) => any} T
|
|
75
|
+
* @param {Renderer | null} renderer
|
|
76
|
+
* @param {T} fn
|
|
77
|
+
* @returns {T}
|
|
78
|
+
*/
|
|
79
|
+
export function renderer_snippet(renderer, fn) {
|
|
80
|
+
var wrapped = /** @type {T} */ (
|
|
81
|
+
(/** @type {TemplateNode} */ anchor, /** @type {any[]} */ ...args) => {
|
|
82
|
+
if (is_crossing(renderer)) {
|
|
83
|
+
return cross(renderer, anchor, (anchor) => fn(anchor, ...args));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return fn(anchor, ...args);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
/** @type {any} */ (wrapped).__renderer = renderer;
|
|
91
|
+
|
|
92
|
+
return wrapped;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Validates that a snippet can be rendered by a custom renderer. Snippets compiled with
|
|
97
|
+
* custom renderer support know which renderer they belong to and can cross renderer
|
|
98
|
+
* boundaries; anything else (e.g. snippets from components compiled without the
|
|
99
|
+
* `experimental.customRenderer` option) can only be rendered by the DOM.
|
|
100
|
+
* @template {((...args: any[]) => void) | null | undefined} T
|
|
101
|
+
* @param {T} fn
|
|
102
|
+
* @returns {T}
|
|
103
|
+
*/
|
|
104
|
+
export function validate_snippet_renderer(fn) {
|
|
105
|
+
if (fn != null && !has_own_property.call(fn, '__renderer')) {
|
|
106
|
+
e.snippet_renderer_mismatch();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return fn;
|
|
110
|
+
}
|
|
111
|
+
|
|
66
112
|
/**
|
|
67
113
|
* Create a snippet programmatically
|
|
68
114
|
* @template {unknown[]} Params
|
|
@@ -75,6 +121,9 @@ export function wrap_snippet(component, fn) {
|
|
|
75
121
|
export function createRawSnippet(fn) {
|
|
76
122
|
// @ts-expect-error the types are a lie
|
|
77
123
|
return (/** @type {TemplateNode} */ anchor, /** @type {Getters<Params>} */ ...params) => {
|
|
124
|
+
if (current_renderer != null) {
|
|
125
|
+
e.invalid_snippet_in_custom_renderer();
|
|
126
|
+
}
|
|
78
127
|
var snippet = fn(...params);
|
|
79
128
|
|
|
80
129
|
/** @type {Element} */
|
|
@@ -88,11 +137,11 @@ export function createRawSnippet(fn) {
|
|
|
88
137
|
var fragment = create_fragment_from_html(html);
|
|
89
138
|
element = /** @type {Element} */ (get_first_child(fragment));
|
|
90
139
|
|
|
91
|
-
if (DEV && (get_next_sibling(element) !== null || element
|
|
140
|
+
if (DEV && (get_next_sibling(element) !== null || node_type(element) !== ELEMENT_NODE)) {
|
|
92
141
|
w.invalid_raw_snippet_render();
|
|
93
142
|
}
|
|
94
143
|
|
|
95
|
-
anchor
|
|
144
|
+
insert_before(anchor, element);
|
|
96
145
|
}
|
|
97
146
|
|
|
98
147
|
if (DEV && dev_stack !== null) {
|