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
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
/** @import { ComponentContext, Effect, EffectNodes, TemplateNode } from '#client' */
|
|
2
2
|
/** @import { Component, ComponentType, SvelteComponent, MountOptions } from '../../index.js' */
|
|
3
|
+
/** @import { Renderer } from './custom-renderer/types.js' */
|
|
3
4
|
import { DEV } from 'esm-env';
|
|
4
5
|
import {
|
|
5
6
|
clear_text_content,
|
|
6
7
|
create_text,
|
|
7
8
|
get_first_child,
|
|
8
9
|
get_next_sibling,
|
|
9
|
-
|
|
10
|
+
append_child,
|
|
11
|
+
get_parent_node,
|
|
12
|
+
remove_child,
|
|
13
|
+
set_node_value,
|
|
14
|
+
get_node_value,
|
|
15
|
+
node_type
|
|
10
16
|
} from './dom/operations.js';
|
|
11
17
|
import { HYDRATION_END, HYDRATION_ERROR, HYDRATION_START } from '../../constants.js';
|
|
12
18
|
import { active_effect } from './runtime.js';
|
|
13
19
|
import { push, pop, component_context, mark_as_component } from './context.js';
|
|
14
20
|
import { component_root } from './reactivity/effects.js';
|
|
15
21
|
import { hydrate_node, hydrating, set_hydrate_node, set_hydrating } from './dom/hydration.js';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
all_registered_events,
|
|
19
|
-
handle_event_propagation,
|
|
20
|
-
root_event_handles
|
|
21
|
-
} from './dom/elements/events.js';
|
|
22
|
+
import { listen_to_delegated_events } from './dom/elements/events.js';
|
|
22
23
|
import * as w from './warnings.js';
|
|
23
24
|
import * as e from './errors.js';
|
|
24
25
|
import { assign_nodes } from './dom/template.js';
|
|
25
|
-
import { is_passive_event } from '../../utils.js';
|
|
26
26
|
import { COMMENT_NODE, TEXT_CACHE } from './constants.js';
|
|
27
27
|
import { boundary } from './dom/blocks/boundary.js';
|
|
28
|
+
import { push_renderer, pop_renderer } from './custom-renderer/state.js';
|
|
29
|
+
import { async_mode_flag, custom_renderers_flag } from '../flags/index.js';
|
|
30
|
+
import { current_batch } from './reactivity/batch.js';
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* This is normally true — block effects should run their intro transitions —
|
|
@@ -47,9 +50,9 @@ export function set_text(text, value) {
|
|
|
47
50
|
// For objects, we apply string coercion (which might make things like $state array references in the template reactive) before diffing
|
|
48
51
|
var str = value == null ? '' : typeof value === 'object' ? `${value}` : value;
|
|
49
52
|
// prettier-ignore
|
|
50
|
-
if (str !== (/** @type {any} */ (text)[TEXT_CACHE] ??= text
|
|
53
|
+
if (str !== (/** @type {any} */ (text)[TEXT_CACHE] ??= get_node_value(text))) {
|
|
51
54
|
/** @type {any} */ (text)[TEXT_CACHE] = str;
|
|
52
|
-
text
|
|
55
|
+
set_node_value(text, `${str}`);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -59,8 +62,9 @@ export function set_text(text, value) {
|
|
|
59
62
|
*
|
|
60
63
|
* @template {Record<string, any>} Props
|
|
61
64
|
* @template {Record<string, any>} Exports
|
|
65
|
+
* @template [Renderer=undefined]
|
|
62
66
|
* @param {ComponentType<SvelteComponent<Props>> | Component<Props, Exports, any>} component
|
|
63
|
-
* @param {MountOptions<Props>} options
|
|
67
|
+
* @param {MountOptions<Props, Renderer>} options
|
|
64
68
|
* @returns {Exports}
|
|
65
69
|
*/
|
|
66
70
|
export function mount(component, options) {
|
|
@@ -93,7 +97,6 @@ export function mount(component, options) {
|
|
|
93
97
|
* @returns {Exports}
|
|
94
98
|
*/
|
|
95
99
|
export function hydrate(component, options) {
|
|
96
|
-
init_operations();
|
|
97
100
|
options.intro = options.intro ?? false;
|
|
98
101
|
const target = options.target;
|
|
99
102
|
const was_hydrating = hydrating;
|
|
@@ -104,7 +107,7 @@ export function hydrate(component, options) {
|
|
|
104
107
|
|
|
105
108
|
while (
|
|
106
109
|
anchor &&
|
|
107
|
-
(anchor
|
|
110
|
+
(node_type(anchor) !== COMMENT_NODE || get_node_value(anchor) !== HYDRATION_START)
|
|
108
111
|
) {
|
|
109
112
|
anchor = get_next_sibling(anchor);
|
|
110
113
|
}
|
|
@@ -118,6 +121,15 @@ export function hydrate(component, options) {
|
|
|
118
121
|
|
|
119
122
|
const instance = _mount(component, { ...options, anchor });
|
|
120
123
|
|
|
124
|
+
// The server rendered the hydrated DOM with the state that hydration ran with (set before `hydrate()`,
|
|
125
|
+
// or while hydrating, e.g. by lazily initialized state), so that state is the real world from now on.
|
|
126
|
+
// This is what happens when mounting, too, where the batch commits right away because the root boundary
|
|
127
|
+
// is pending. Otherwise, while the hydration batch waits for async work, other batches' views would undo
|
|
128
|
+
// those writes — e.g. that of a pending boundary's content, which renders in a batch of its own
|
|
129
|
+
if (async_mode_flag && current_batch !== null) {
|
|
130
|
+
current_batch.commit_writes();
|
|
131
|
+
}
|
|
132
|
+
|
|
121
133
|
set_hydrating(false);
|
|
122
134
|
|
|
123
135
|
return /** @type {Exports} */ (instance);
|
|
@@ -138,8 +150,6 @@ export function hydrate(component, options) {
|
|
|
138
150
|
e.hydration_failed();
|
|
139
151
|
}
|
|
140
152
|
|
|
141
|
-
// If an error occurred above, the operations might not yet have been initialised.
|
|
142
|
-
init_operations();
|
|
143
153
|
clear_text_content(target);
|
|
144
154
|
|
|
145
155
|
set_hydrating(false);
|
|
@@ -150,27 +160,43 @@ export function hydrate(component, options) {
|
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
162
|
|
|
153
|
-
/**
|
|
154
|
-
|
|
163
|
+
/**
|
|
164
|
+
* @template {Record<string, any>} Exports
|
|
165
|
+
* @param {ComponentType<SvelteComponent<any>> | Component<any>} Component
|
|
166
|
+
* @param {MountOptions<any, any> & { renderer?: Renderer }} options
|
|
167
|
+
* @returns {Exports}
|
|
168
|
+
*/
|
|
169
|
+
function _mount(Component, options) {
|
|
170
|
+
if (custom_renderers_flag && options.renderer) {
|
|
171
|
+
var previous_renderer = push_renderer(options.renderer);
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
return _mount_inner(Component, options);
|
|
175
|
+
} finally {
|
|
176
|
+
pop_renderer(previous_renderer);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return _mount_inner(Component, options);
|
|
181
|
+
}
|
|
155
182
|
|
|
156
183
|
/**
|
|
157
184
|
* @template {Record<string, any>} Exports
|
|
158
185
|
* @param {ComponentType<SvelteComponent<any>> | Component<any>} Component
|
|
159
|
-
* @param {MountOptions} options
|
|
186
|
+
* @param {MountOptions<any, any> & { renderer?: Renderer }} options
|
|
160
187
|
* @returns {Exports}
|
|
161
188
|
*/
|
|
162
|
-
function
|
|
189
|
+
function _mount_inner(
|
|
163
190
|
Component,
|
|
164
|
-
{ target, anchor, props = {}, events, context, intro = true, transformError }
|
|
191
|
+
{ target, anchor, props = {}, events, context, intro = true, transformError, renderer }
|
|
165
192
|
) {
|
|
166
|
-
init_operations();
|
|
167
|
-
|
|
168
193
|
/** @type {Exports} */
|
|
169
194
|
// @ts-expect-error will be defined because the render effect runs synchronously
|
|
170
195
|
var component = undefined;
|
|
171
196
|
|
|
172
197
|
var unmount = component_root(() => {
|
|
173
|
-
var anchor_node =
|
|
198
|
+
var anchor_node =
|
|
199
|
+
anchor ?? /** @type {Text} */ (append_child(/** @type {Node} */ (target), create_text()));
|
|
174
200
|
|
|
175
201
|
boundary(
|
|
176
202
|
/** @type {TemplateNode} */ (anchor_node),
|
|
@@ -201,8 +227,8 @@ function _mount(
|
|
|
201
227
|
|
|
202
228
|
if (
|
|
203
229
|
hydrate_node === null ||
|
|
204
|
-
hydrate_node
|
|
205
|
-
|
|
230
|
+
node_type(hydrate_node) !== COMMENT_NODE ||
|
|
231
|
+
get_node_value(hydrate_node) !== HYDRATION_END
|
|
206
232
|
) {
|
|
207
233
|
w.hydration_mismatch();
|
|
208
234
|
throw HYDRATION_ERROR;
|
|
@@ -214,72 +240,19 @@ function _mount(
|
|
|
214
240
|
transformError
|
|
215
241
|
);
|
|
216
242
|
|
|
217
|
-
// Setup event delegation _after_ component is mounted - if an error would happen during mount, it would otherwise not be cleaned up
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
for (var i = 0; i < events.length; i++) {
|
|
224
|
-
var event_name = events[i];
|
|
225
|
-
|
|
226
|
-
if (registered_events.has(event_name)) continue;
|
|
227
|
-
registered_events.add(event_name);
|
|
228
|
-
|
|
229
|
-
var passive = is_passive_event(event_name);
|
|
230
|
-
|
|
231
|
-
// Add the event listener to both the container and the document.
|
|
232
|
-
// The container listener ensures we catch events from within in case
|
|
233
|
-
// the outer content stops propagation of the event.
|
|
234
|
-
//
|
|
235
|
-
// The document listener ensures we catch events that originate from elements that were
|
|
236
|
-
// manually moved outside of the container (e.g. via manual portals).
|
|
237
|
-
for (const node of [target, document]) {
|
|
238
|
-
var counts = listeners.get(node);
|
|
239
|
-
|
|
240
|
-
if (counts === undefined) {
|
|
241
|
-
counts = new Map();
|
|
242
|
-
listeners.set(node, counts);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
var count = counts.get(event_name);
|
|
246
|
-
|
|
247
|
-
if (count === undefined) {
|
|
248
|
-
node.addEventListener(event_name, handle_event_propagation, { passive });
|
|
249
|
-
counts.set(event_name, 1);
|
|
250
|
-
} else {
|
|
251
|
-
counts.set(event_name, count + 1);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
event_handle(array_from(all_registered_events));
|
|
258
|
-
root_event_handles.add(event_handle);
|
|
243
|
+
// Setup event delegation _after_ component is mounted - if an error would happen during mount, it would otherwise not be cleaned up.
|
|
244
|
+
// When mounting with a custom renderer the target isn't a DOM node; any DOM content inside it is rendered
|
|
245
|
+
// into DOM containers that become delegation roots themselves (see `cross`)
|
|
246
|
+
var stop_listening = renderer
|
|
247
|
+
? null
|
|
248
|
+
: listen_to_delegated_events(/** @type {EventTarget} */ (target));
|
|
259
249
|
|
|
260
250
|
return () => {
|
|
261
|
-
|
|
262
|
-
for (const node of [target, document]) {
|
|
263
|
-
var counts = /** @type {Map<string, number>} */ (listeners.get(node));
|
|
264
|
-
var count = /** @type {number} */ (counts.get(event_name));
|
|
265
|
-
|
|
266
|
-
if (--count == 0) {
|
|
267
|
-
node.removeEventListener(event_name, handle_event_propagation);
|
|
268
|
-
counts.delete(event_name);
|
|
269
|
-
|
|
270
|
-
if (counts.size === 0) {
|
|
271
|
-
listeners.delete(node);
|
|
272
|
-
}
|
|
273
|
-
} else {
|
|
274
|
-
counts.set(event_name, count);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
root_event_handles.delete(event_handle);
|
|
251
|
+
stop_listening?.();
|
|
280
252
|
|
|
281
253
|
if (anchor_node !== anchor) {
|
|
282
|
-
|
|
254
|
+
var parent = get_parent_node(/** @type {Node} */ (anchor_node));
|
|
255
|
+
if (parent) remove_child(parent, /** @type {ChildNode} */ (anchor_node));
|
|
283
256
|
}
|
|
284
257
|
};
|
|
285
258
|
});
|