Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: inline start and end node properties into effect #12878

Merged
merged 8 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-bugs-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: inline start and end node properties into effect
10 changes: 5 additions & 5 deletions packages/svelte/src/internal/client/dom/blocks/each.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { EachItem, EachState, Effect, EffectNodes, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */
/** @import { EachItem, EachState, Effect, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */
import {
EACH_INDEX_REACTIVE,
EACH_IS_ANIMATED,
Expand Down Expand Up @@ -288,7 +288,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
item = items.get(key);

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

prev = create_item(
child_anchor,
Expand Down Expand Up @@ -509,10 +509,10 @@ function create_item(anchor, state, prev, next, value, key, index, render_fn, fl
* @param {Text | Element | Comment} anchor
*/
function move(item, next, anchor) {
var end = item.next ? /** @type {EffectNodes} */ (item.next.e.nodes).start : anchor;
var end = item.next ? /** @type {TemplateNode} */ (item.next.e.nodes_start) : anchor;

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

while (node !== end) {
var next_node = /** @type {TemplateNode} */ (get_next_sibling(node));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { Effect, EffectNodes, TemplateNode } from '#client' */
/** @import { Effect, TemplateNode } from '#client' */
import { FILENAME, NAMESPACE_SVG } from '../../../../constants.js';
import {
hydrate_next,
Expand Down Expand Up @@ -138,7 +138,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
}

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

anchor.before(element);
});
Expand Down
10 changes: 7 additions & 3 deletions packages/svelte/src/internal/client/dom/template.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { Effect, EffectNodes, TemplateNode } from '#client' */
/** @import { Effect, TemplateNode } from '#client' */
import { hydrate_next, hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
import { create_text, get_first_child } from './operations.js';
import { create_fragment_from_html } from './reconciler.js';
Expand All @@ -11,7 +11,11 @@ import { queue_micro_task } from './task.js';
* @param {TemplateNode | null} end
*/
export function assign_nodes(start, end) {
/** @type {Effect} */ (current_effect).nodes ??= { start, end };
var effect = /** @type {Effect} */ (current_effect);
if (effect.nodes_start === null) {
effect.nodes_start = start;
effect.nodes_end = end;
}
}

/**
Expand Down Expand Up @@ -255,7 +259,7 @@ export function comment() {
*/
export function append(anchor, dom) {
if (hydrating) {
/** @type {Effect & { nodes: EffectNodes }} */ (current_effect).nodes.end = hydrate_node;
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node;
hydrate_next();
return;
}
Expand Down
14 changes: 8 additions & 6 deletions packages/svelte/src/internal/client/reactivity/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function create_effect(type, fn, sync, push = true) {
var effect = {
ctx: current_component_context,
deps: null,
nodes: null,
nodes_start: null,
nodes_end: null,
f: type | DIRTY,
first: null,
fn,
Expand Down Expand Up @@ -135,7 +136,7 @@ function create_effect(type, fn, sync, push = true) {
sync &&
effect.deps === null &&
effect.first === null &&
effect.nodes === null &&
effect.nodes_start === null &&
effect.teardown === null;

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

if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null) {
if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes_start !== null) {
/** @type {TemplateNode | null} */
var node = effect.nodes.start;
var end = effect.nodes.end;
var node = effect.nodes_start;
var end = effect.nodes_end;

while (node !== null) {
/** @type {TemplateNode | null} */
Expand Down Expand Up @@ -398,7 +399,8 @@ export function destroy_effect(effect, remove_dom = true) {
effect.deps =
effect.parent =
effect.fn =
effect.nodes =
effect.nodes_start =
effect.nodes_end =
null;
}

Expand Down
8 changes: 2 additions & 6 deletions packages/svelte/src/internal/client/reactivity/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export interface Derived<V = unknown> extends Value<V>, Reaction {
deriveds: null | Derived[];
}

export interface EffectNodes {
start: TemplateNode;
end: null | TemplateNode;
}

export interface Effect extends Reaction {
parent: Effect | null;
/**
Expand All @@ -47,7 +42,8 @@ export interface Effect extends Reaction {
* block is reconciled. In the case of a single text/element node,
* `start` and `end` will be the same.
*/
nodes: null | EffectNodes;
nodes_start: null | TemplateNode;
nodes_end: null | TemplateNode;
/** The associated component context */
ctx: null | ComponentContext;
/** The effect function */
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @import { ComponentContext, Effect, EffectNodes, TemplateNode } from '#client' */
/** @import { ComponentContext, Effect, TemplateNode } from '#client' */
/** @import { Component, ComponentType, SvelteComponent } from '../../index.js' */
import { DEV } from 'esm-env';
import {
Expand Down Expand Up @@ -246,7 +246,7 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
should_intro = true;

if (hydrating) {
/** @type {Effect & { nodes: EffectNodes }} */ (current_effect).nodes.end = hydrate_node;
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node;
}

if (context) {
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ function flush_queued_effects(effects) {
// don't know if we need to keep them until they are executed. Doing the check
// here (rather than in `update_effect`) allows us to skip the work for
// immediate effects.
if (effect.deps === null && effect.first === null && effect.nodes === null) {
if (effect.deps === null && effect.first === null && effect.nodes_start === null) {
if (effect.teardown === null) {
// remove this effect from the graph
unlink_effect(effect);
Expand Down
Loading