Skip to content

Commit 19a35c6

Browse files
trueadmConduitry
andauthored
chore: inline start and end node properties into effect (#12878)
* chore: inline start and end node properties into effect * Revert "chore: set `binding.kind` before analysis (#12843)" This reverts commit 19beb77. * name better * oops * revert * revert * revert --------- Co-authored-by: Conduitry <[email protected]>
1 parent 8175588 commit 19a35c6

File tree

8 files changed

+32
-25
lines changed

8 files changed

+32
-25
lines changed

.changeset/eighty-bugs-fetch.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: inline start and end node properties into effect

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { EachItem, EachState, Effect, EffectNodes, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */
1+
/** @import { EachItem, EachState, Effect, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */
22
import {
33
EACH_INDEX_REACTIVE,
44
EACH_IS_ANIMATED,
@@ -288,7 +288,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
288288
item = items.get(key);
289289

290290
if (item === undefined) {
291-
var child_anchor = current ? /** @type {EffectNodes} */ (current.e.nodes).start : anchor;
291+
var child_anchor = current ? /** @type {TemplateNode} */ (current.e.nodes_start) : anchor;
292292

293293
prev = create_item(
294294
child_anchor,
@@ -513,10 +513,10 @@ function create_item(anchor, state, prev, next, value, key, index, render_fn, fl
513513
* @param {Text | Element | Comment} anchor
514514
*/
515515
function move(item, next, anchor) {
516-
var end = item.next ? /** @type {EffectNodes} */ (item.next.e.nodes).start : anchor;
516+
var end = item.next ? /** @type {TemplateNode} */ (item.next.e.nodes_start) : anchor;
517517

518-
var dest = next ? /** @type {EffectNodes} */ (next.e.nodes).start : anchor;
519-
var node = /** @type {EffectNodes} */ (item.e.nodes).start;
518+
var dest = next ? /** @type {TemplateNode} */ (next.e.nodes_start) : anchor;
519+
var node = /** @type {TemplateNode} */ (item.e.nodes_start);
520520

521521
while (node !== end) {
522522
var next_node = /** @type {TemplateNode} */ (get_next_sibling(node));

packages/svelte/src/internal/client/dom/blocks/svelte-element.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { Effect, EffectNodes, TemplateNode } from '#client' */
1+
/** @import { Effect, TemplateNode } from '#client' */
22
import { FILENAME, NAMESPACE_SVG } from '../../../../constants.js';
33
import {
44
hydrate_next,
@@ -138,7 +138,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
138138
}
139139

140140
// we do this after calling `render_fn` so that child effects don't override `nodes.end`
141-
/** @type {Effect & { nodes: EffectNodes }} */ (current_effect).nodes.end = element;
141+
/** @type {Effect} */ (current_effect).nodes_end = element;
142142

143143
anchor.before(element);
144144
});

packages/svelte/src/internal/client/dom/template.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { Effect, EffectNodes, TemplateNode } from '#client' */
1+
/** @import { Effect, TemplateNode } from '#client' */
22
import { hydrate_next, hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
33
import { create_text, get_first_child } from './operations.js';
44
import { create_fragment_from_html } from './reconciler.js';
@@ -11,7 +11,11 @@ import { queue_micro_task } from './task.js';
1111
* @param {TemplateNode | null} end
1212
*/
1313
export function assign_nodes(start, end) {
14-
/** @type {Effect} */ (current_effect).nodes ??= { start, end };
14+
var effect = /** @type {Effect} */ (current_effect);
15+
if (effect.nodes_start === null) {
16+
effect.nodes_start = start;
17+
effect.nodes_end = end;
18+
}
1519
}
1620

1721
/**
@@ -255,7 +259,7 @@ export function comment() {
255259
*/
256260
export function append(anchor, dom) {
257261
if (hydrating) {
258-
/** @type {Effect & { nodes: EffectNodes }} */ (current_effect).nodes.end = hydrate_node;
262+
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node;
259263
hydrate_next();
260264
return;
261265
}

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function create_effect(type, fn, sync, push = true) {
9595
var effect = {
9696
ctx: current_component_context,
9797
deps: null,
98-
nodes: null,
98+
nodes_start: null,
99+
nodes_end: null,
99100
f: type | DIRTY,
100101
first: null,
101102
fn,
@@ -135,7 +136,7 @@ function create_effect(type, fn, sync, push = true) {
135136
sync &&
136137
effect.deps === null &&
137138
effect.first === null &&
138-
effect.nodes === null &&
139+
effect.nodes_start === null &&
139140
effect.teardown === null;
140141

141142
if (!inert && !is_root && push) {
@@ -355,10 +356,10 @@ export function execute_effect_teardown(effect) {
355356
export function destroy_effect(effect, remove_dom = true) {
356357
var removed = false;
357358

358-
if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null) {
359+
if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes_start !== null) {
359360
/** @type {TemplateNode | null} */
360-
var node = effect.nodes.start;
361-
var end = effect.nodes.end;
361+
var node = effect.nodes_start;
362+
var end = effect.nodes_end;
362363

363364
while (node !== null) {
364365
/** @type {TemplateNode | null} */
@@ -400,7 +401,8 @@ export function destroy_effect(effect, remove_dom = true) {
400401
effect.deps =
401402
effect.parent =
402403
effect.fn =
403-
effect.nodes =
404+
effect.nodes_start =
405+
effect.nodes_end =
404406
null;
405407
}
406408

packages/svelte/src/internal/client/reactivity/types.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export interface Derived<V = unknown> extends Value<V>, Reaction {
3434
deriveds: null | Derived[];
3535
}
3636

37-
export interface EffectNodes {
38-
start: TemplateNode;
39-
end: null | TemplateNode;
40-
}
41-
4237
export interface Effect extends Reaction {
4338
parent: Effect | null;
4439
/**
@@ -47,7 +42,8 @@ export interface Effect extends Reaction {
4742
* block is reconciled. In the case of a single text/element node,
4843
* `start` and `end` will be the same.
4944
*/
50-
nodes: null | EffectNodes;
45+
nodes_start: null | TemplateNode;
46+
nodes_end: null | TemplateNode;
5147
/** The associated component context */
5248
ctx: null | ComponentContext;
5349
/** The effect function */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { ComponentContext, Effect, EffectNodes, TemplateNode } from '#client' */
1+
/** @import { ComponentContext, Effect, TemplateNode } from '#client' */
22
/** @import { Component, ComponentType, SvelteComponent } from '../../index.js' */
33
import { DEV } from 'esm-env';
44
import {
@@ -246,7 +246,7 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
246246
should_intro = true;
247247

248248
if (hydrating) {
249-
/** @type {Effect & { nodes: EffectNodes }} */ (current_effect).nodes.end = hydrate_node;
249+
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node;
250250
}
251251

252252
if (context) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function flush_queued_effects(effects) {
497497
// don't know if we need to keep them until they are executed. Doing the check
498498
// here (rather than in `update_effect`) allows us to skip the work for
499499
// immediate effects.
500-
if (effect.deps === null && effect.first === null && effect.nodes === null) {
500+
if (effect.deps === null && effect.first === null && effect.nodes_start === null) {
501501
if (effect.teardown === null) {
502502
// remove this effect from the graph
503503
unlink_effect(effect);

0 commit comments

Comments
 (0)