Skip to content

Commit feabe20

Browse files
committed
Merge branch 'main' into skip-site-deploy
2 parents 9b9c082 + a990e57 commit feabe20

File tree

24 files changed

+345
-242
lines changed

24 files changed

+345
-242
lines changed

.changeset/chilly-dolphins-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: remove selector api

.changeset/eight-steaks-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: correct update_block index type

.changeset/khaki-mails-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: tighten up signals implementation

.changeset/quiet-camels-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: improve keyblock treeshaking

packages/svelte/src/compiler/phases/3-transform/client/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ export const function_visitor = (node, context) => {
251251
const in_constructor = parent.type === 'MethodDefinition' && parent.kind === 'constructor';
252252

253253
state = { ...context.state, in_constructor };
254+
} else {
255+
state = { ...context.state, in_constructor: false };
254256
}
255257

256258
if (metadata?.hoistable === true) {

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,19 +2227,34 @@ export const template_visitors = {
22272227
declarations.push(b.let(node.index, index));
22282228
}
22292229

2230-
context.state.after_update.push(
2231-
b.stmt(
2232-
b.call(
2233-
'$.each',
2234-
context.state.node,
2235-
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2236-
b.literal(each_type),
2237-
key_function,
2238-
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children))),
2239-
else_block
2230+
if ((each_type & EACH_KEYED) !== 0) {
2231+
context.state.after_update.push(
2232+
b.stmt(
2233+
b.call(
2234+
'$.each_keyed',
2235+
context.state.node,
2236+
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2237+
b.literal(each_type),
2238+
key_function,
2239+
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children))),
2240+
else_block
2241+
)
22402242
)
2241-
)
2242-
);
2243+
);
2244+
} else {
2245+
context.state.after_update.push(
2246+
b.stmt(
2247+
b.call(
2248+
'$.each_indexed',
2249+
context.state.node,
2250+
each_node_meta.array_name ? each_node_meta.array_name : b.thunk(collection),
2251+
b.literal(each_type),
2252+
b.arrow([b.id('$$anchor'), item, index], b.block(declarations.concat(children))),
2253+
else_block
2254+
)
2255+
)
2256+
);
2257+
}
22432258
},
22442259
IfBlock(node, context) {
22452260
context.state.template.push('<!>');

packages/svelte/src/internal/client/operations.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ const has_browser_globals = typeof window !== 'undefined';
88
// than megamorphic.
99
const node_prototype = /** @type {Node} */ (has_browser_globals ? Node.prototype : {});
1010
const element_prototype = /** @type {Element} */ (has_browser_globals ? Element.prototype : {});
11-
const event_target_prototype = /** @type {EventTarget} */ (
12-
has_browser_globals ? EventTarget.prototype : {}
13-
);
11+
const text_prototype = /** @type {Text} */ (has_browser_globals ? Text.prototype : {});
1412
const map_prototype = Map.prototype;
1513
const append_child_method = node_prototype.appendChild;
1614
const clone_node_method = node_prototype.cloneNode;
1715
const map_set_method = map_prototype.set;
1816
const map_get_method = map_prototype.get;
1917
const map_delete_method = map_prototype.delete;
20-
// @ts-expect-error improve perf of expando on DOM nodes for events
21-
event_target_prototype.__click = undefined;
22-
// @ts-expect-error improve perf of expando on DOM textValue updates
23-
event_target_prototype.__nodeValue = ' ';
18+
// @ts-expect-error improve perf of expando on DOM events
19+
element_prototype.__click = undefined;
20+
// @ts-expect-error improve perf of expando on DOM text updates
21+
text_prototype.__nodeValue = ' ';
2422
// @ts-expect-error improve perf of expando on DOM className updates
25-
event_target_prototype.__className = '';
23+
element_prototype.__className = '';
2624

2725
const first_child_get = /** @type {(this: Node) => ChildNode | null} */ (
2826
// @ts-ignore
@@ -162,11 +160,10 @@ export function set_class_name(node, class_name) {
162160
/**
163161
* @template {Node} N
164162
* @param {N} node
165-
* @param {string} text
166163
* @returns {void}
167164
*/
168-
export function text_content(node, text) {
169-
text_content_set.call(node, text);
165+
export function clear_text_content(node) {
166+
text_content_set.call(node, '');
170167
}
171168

172169
/** @param {string} name */

packages/svelte/src/internal/client/reconciler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { append_child, map_get, map_set, text_content } from './operations.js';
1+
import { append_child, map_get, map_set, clear_text_content } from './operations.js';
22
import {
33
current_hydration_fragment,
44
get_hydration_fragment,
@@ -198,7 +198,7 @@ export function reconcile_indexed_array(
198198
b_blocks = [];
199199
// Remove old blocks
200200
if (is_controlled && a !== 0) {
201-
text_content(dom, '');
201+
clear_text_content(dom);
202202
}
203203
while (index < length) {
204204
block = a_blocks[index++];
@@ -260,9 +260,9 @@ export function reconcile_indexed_array(
260260
* @param {Element | Comment | Text} dom
261261
* @param {boolean} is_controlled
262262
* @param {(anchor: null, item: V, index: number | import('./types.js').Signal<number>) => void} render_fn
263-
* @param {Array<string> | null} keys
264263
* @param {number} flags
265264
* @param {boolean} apply_transitions
265+
* @param {Array<string> | null} keys
266266
* @returns {void}
267267
*/
268268
export function reconcile_tracked_array(
@@ -271,9 +271,9 @@ export function reconcile_tracked_array(
271271
dom,
272272
is_controlled,
273273
render_fn,
274-
keys,
275274
flags,
276-
apply_transitions
275+
apply_transitions,
276+
keys
277277
) {
278278
var a_blocks = each_block.items;
279279
const is_computed_key = keys !== null;
@@ -295,7 +295,7 @@ export function reconcile_tracked_array(
295295
b_blocks = [];
296296
// Remove old blocks
297297
if (is_controlled && a !== 0) {
298-
text_content(dom, '');
298+
clear_text_content(dom);
299299
}
300300
while (a > 0) {
301301
block = a_blocks[--a];

packages/svelte/src/internal/client/render.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import {
6868
hydrate_block_anchor,
6969
set_current_hydration_fragment
7070
} from './hydration.js';
71-
import { array_from, define_property, get_descriptor, get_descriptors, is_array } from './utils.js';
71+
import { array_from, define_property, get_descriptor, is_array } from './utils.js';
7272
import { is_promise } from '../common.js';
7373
import { bind_transition } from './transitions.js';
7474

@@ -1270,15 +1270,15 @@ function handle_event_propagation(root_element, event) {
12701270
}
12711271

12721272
// composedPath contains list of nodes the event has propagated through.
1273-
// We check __handled_event_at to skip all nodes below it in case this is a
1274-
// parent of the __handled_event_at node, which indicates that there's nested
1273+
// We check __root to skip all nodes below it in case this is a
1274+
// parent of the __root node, which indicates that there's nested
12751275
// mounted apps. In this case we don't want to trigger events multiple times.
12761276
// We're deliberately not skipping if the index is the same or higher, because
12771277
// someone could create an event programmatically and emit it multiple times,
12781278
// in which case we want to handle the whole propagation chain properly each time.
12791279
let path_idx = 0;
12801280
// @ts-expect-error is added below
1281-
const handled_at = event.__handled_event_at;
1281+
const handled_at = event.__root;
12821282
if (handled_at) {
12831283
const at_idx = path.indexOf(handled_at);
12841284
if (at_idx < path.indexOf(root_element)) {
@@ -1317,7 +1317,7 @@ function handle_event_propagation(root_element, event) {
13171317
}
13181318

13191319
// @ts-expect-error is used above
1320-
event.__handled_event_at = root_element;
1320+
event.__root = root_element;
13211321
}
13221322

13231323
/**
@@ -2078,7 +2078,7 @@ function get_first_element(block) {
20782078
/**
20792079
* @param {import('./types.js').EachItemBlock} block
20802080
* @param {any} item
2081-
* @param {import('./types.js').MaybeSignal<number>} index
2081+
* @param {number} index
20822082
* @param {number} type
20832083
* @returns {void}
20842084
*/
@@ -2093,7 +2093,6 @@ export function update_each_item_block(block, item, index, type) {
20932093
let prev_index = block.index;
20942094
if (index_is_reactive) {
20952095
prev_index = /** @type {import('./types.js').Signal<number>} */ (prev_index).value;
2096-
index = /** @type {import('./types.js').Signal<number>} */ (index).value;
20972096
}
20982097
const items = block.parent.items;
20992098
if (prev_index !== index && /** @type {number} */ (index) < items.length) {
@@ -2263,9 +2262,10 @@ export function each_item_block(item, key, index, render_fn, flags) {
22632262
* @param {null | ((item: V) => string)} key_fn
22642263
* @param {(anchor: null, item: V, index: import('./types.js').MaybeSignal<number>) => void} render_fn
22652264
* @param {null | ((anchor: Node) => void)} fallback_fn
2265+
* @param {typeof reconcile_indexed_array | reconcile_tracked_array} reconcile_fn
22662266
* @returns {void}
22672267
*/
2268-
export function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn) {
2268+
function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, reconcile_fn) {
22692269
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
22702270
const block = create_each_block(flags, anchor_node);
22712271

@@ -2385,20 +2385,7 @@ export function each(anchor_node, collection, flags, key_fn, render_fn, fallback
23852385
const flags = block.flags;
23862386
const is_controlled = (flags & EACH_IS_CONTROLLED) !== 0;
23872387
const anchor_node = block.anchor;
2388-
if ((flags & EACH_KEYED) !== 0) {
2389-
reconcile_tracked_array(
2390-
array,
2391-
block,
2392-
anchor_node,
2393-
is_controlled,
2394-
render_fn,
2395-
keys,
2396-
flags,
2397-
true
2398-
);
2399-
} else {
2400-
reconcile_indexed_array(array, block, anchor_node, is_controlled, render_fn, flags, true);
2401-
}
2388+
reconcile_fn(array, block, anchor_node, is_controlled, render_fn, flags, true, keys);
24022389
},
24032390
block,
24042391
true
@@ -2420,12 +2407,39 @@ export function each(anchor_node, collection, flags, key_fn, render_fn, fallback
24202407
fallback = fallback.prev;
24212408
}
24222409
// Clear the array
2423-
reconcile_indexed_array([], block, anchor_node, is_controlled, render_fn, flags, false);
2410+
reconcile_fn([], block, anchor_node, is_controlled, render_fn, flags, false, keys);
24242411
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (render));
24252412
});
24262413
block.effect = each;
24272414
}
24282415

2416+
/**
2417+
* @template V
2418+
* @param {Element | Comment} anchor_node
2419+
* @param {() => V[]} collection
2420+
* @param {number} flags
2421+
* @param {null | ((item: V) => string)} key_fn
2422+
* @param {(anchor: null, item: V, index: import('./types.js').MaybeSignal<number>) => void} render_fn
2423+
* @param {null | ((anchor: Node) => void)} fallback_fn
2424+
* @returns {void}
2425+
*/
2426+
export function each_keyed(anchor_node, collection, flags, key_fn, render_fn, fallback_fn) {
2427+
each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, reconcile_tracked_array);
2428+
}
2429+
2430+
/**
2431+
* @template V
2432+
* @param {Element | Comment} anchor_node
2433+
* @param {() => V[]} collection
2434+
* @param {number} flags
2435+
* @param {(anchor: null, item: V, index: import('./types.js').MaybeSignal<number>) => void} render_fn
2436+
* @param {null | ((anchor: Node) => void)} fallback_fn
2437+
* @returns {void}
2438+
*/
2439+
export function each_indexed(anchor_node, collection, flags, render_fn, fallback_fn) {
2440+
each(anchor_node, collection, flags, null, render_fn, fallback_fn, reconcile_indexed_array);
2441+
}
2442+
24292443
/**
24302444
* @param {Element | Text | Comment} anchor
24312445
* @param {boolean} is_html

0 commit comments

Comments
 (0)