chore: more non-essential changes from #11690 (#11750)

pull/11752/head
Rich Harris 1 year ago committed by GitHub
parent 329c10eb6c
commit 50cc8a4848
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,7 +2,6 @@ import { namespace_svg } from '../../../../constants.js';
import { hydrate_anchor, hydrate_nodes, hydrating } from '../hydration.js'; import { hydrate_anchor, hydrate_nodes, hydrating } from '../hydration.js';
import { empty } from '../operations.js'; import { empty } from '../operations.js';
import { render_effect } from '../../reactivity/effects.js'; import { render_effect } from '../../reactivity/effects.js';
import { remove } from '../reconciler.js';
/** /**
* @param {Element | Text | Comment} anchor * @param {Element | Text | Comment} anchor
@ -60,7 +59,7 @@ export function css_props(anchor, is_html, props, component) {
}); });
return () => { return () => {
remove(element); element.remove();
}; };
}); });
} }

@ -25,7 +25,6 @@ import {
import { source, mutable_source, set } from '../../reactivity/sources.js'; import { source, mutable_source, set } from '../../reactivity/sources.js';
import { is_array, is_frozen } from '../../utils.js'; import { is_array, is_frozen } from '../../utils.js';
import { INERT, STATE_SYMBOL } from '../../constants.js'; import { INERT, STATE_SYMBOL } from '../../constants.js';
import { push_template_node } from '../template.js';
/** /**
* The row of a keyed each block that is currently updating. We track this * The row of a keyed each block that is currently updating. We track this
@ -407,7 +406,7 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
for (var i = 0; i < to_destroy.length; i += 1) { for (var i = 0; i < to_destroy.length; i += 1) {
var item = to_destroy[i]; var item = to_destroy[i];
items.delete(item.k); items.delete(item.k);
remove(item.o); item.o.remove();
link(item.prev, item.next); link(item.prev, item.next);
} }
}); });

@ -51,118 +51,112 @@ export function element(anchor, get_tag, is_svg, render_fn, get_namespace, locat
const filename = DEV && location && current_component_context?.function.filename; const filename = DEV && location && current_component_context?.function.filename;
render_effect(() => { /** @type {string | null} */
/** @type {string | null} */ let tag;
let tag;
/** @type {string | null} */
/** @type {string | null} */ let current_tag;
let current_tag;
/** @type {null | Element} */
/** @type {null | Element} */ let element = null;
let element = null;
/** @type {import('#client').Effect | null} */
/** @type {import('#client').Effect | null} */ let effect;
let effect;
/**
/** * The keyed `{#each ...}` item block, if any, that this element is inside.
* The keyed `{#each ...}` item block, if any, that this element is inside. * We track this so we can set it when changing the element, allowing any
* We track this so we can set it when changing the element, allowing any * `animate:` directive to bind itself to the correct block
* `animate:` directive to bind itself to the correct block */
*/ let each_item_block = current_each_item;
let each_item_block = current_each_item;
block(() => {
block(() => { const next_tag = get_tag() || null;
const next_tag = get_tag() || null; const ns = get_namespace
const ns = get_namespace ? get_namespace()
? get_namespace() : is_svg || next_tag === 'svg'
: is_svg || next_tag === 'svg' ? namespace_svg
? namespace_svg : null;
: null; // Assumption: Noone changes the namespace but not the tag (what would that even mean?)
// Assumption: Noone changes the namespace but not the tag (what would that even mean?) if (next_tag === tag) return;
if (next_tag === tag) return;
// See explanation of `each_item_block` above
// See explanation of `each_item_block` above var previous_each_item = current_each_item;
var previous_each_item = current_each_item; set_current_each_item(each_item_block);
set_current_each_item(each_item_block);
if (effect) {
if (effect) { if (next_tag === null) {
if (next_tag === null) { // start outro
// start outro pause_effect(effect, () => {
pause_effect(effect, () => { effect = null;
effect = null; current_tag = null;
current_tag = null; element?.remove();
element?.remove(); });
}); } else if (next_tag === current_tag) {
} else if (next_tag === current_tag) { // same tag as is currently rendered — abort outro
// same tag as is currently rendered — abort outro resume_effect(effect);
resume_effect(effect); } else {
} else { // tag is changing — destroy immediately, render contents without intro transitions
// tag is changing — destroy immediately, render contents without intro transitions destroy_effect(effect);
destroy_effect(effect); set_should_intro(false);
set_should_intro(false);
}
} }
}
if (next_tag && next_tag !== current_tag) { if (next_tag && next_tag !== current_tag) {
effect = branch(() => { effect = branch(() => {
const prev_element = element; const prev_element = element;
element = hydrating element = hydrating
? /** @type {Element} */ (hydrate_nodes[0]) ? /** @type {Element} */ (hydrate_nodes[0])
: ns : ns
? document.createElementNS(ns, next_tag) ? document.createElementNS(ns, next_tag)
: document.createElement(next_tag); : document.createElement(next_tag);
if (DEV && location) { if (DEV && location) {
// @ts-expect-error // @ts-expect-error
element.__svelte_meta = { element.__svelte_meta = {
loc: { loc: {
file: filename, file: filename,
line: location[0], line: location[0],
column: location[1] column: location[1]
}
};
}
if (render_fn) {
// If hydrating, use the existing ssr comment as the anchor so that the
// inner open and close methods can pick up the existing nodes correctly
var child_anchor = hydrating
? element.firstChild && hydrate_anchor(/** @type {Comment} */ (element.firstChild))
: element.appendChild(empty());
if (hydrating && !element.firstChild) {
// if the element is a void element with content, add an empty
// node to avoid breaking assumptions elsewhere
set_hydrate_nodes([empty()]);
} }
};
}
// `child_anchor` is undefined if this is a void element, but we still if (render_fn) {
// need to call `render_fn` in order to run actions etc. If the element // If hydrating, use the existing ssr comment as the anchor so that the
// contains children, it's a user error (which is warned on elsewhere) // inner open and close methods can pick up the existing nodes correctly
// and the DOM will be silently discarded var child_anchor = hydrating
render_fn(element, child_anchor); ? element.firstChild && hydrate_anchor(/** @type {Comment} */ (element.firstChild))
: element.appendChild(empty());
if (hydrating && !element.firstChild) {
// if the element is a void element with content, add an empty
// node to avoid breaking assumptions elsewhere
set_hydrate_nodes([empty()]);
} }
anchor.before(element); // `child_anchor` is undefined if this is a void element, but we still
// need to call `render_fn` in order to run actions etc. If the element
// contains children, it's a user error (which is warned on elsewhere)
// and the DOM will be silently discarded
render_fn(element, child_anchor);
}
if (prev_element) { anchor.before(element);
swap_block_dom(parent_effect, prev_element, element);
prev_element.remove();
} else if (!hydrating) {
push_template_node(element, parent_effect);
}
});
}
tag = next_tag; if (prev_element) {
if (tag) current_tag = tag; swap_block_dom(parent_effect, prev_element, element);
set_should_intro(true); prev_element.remove();
} else if (!hydrating) {
push_template_node(element, parent_effect);
}
});
}
set_current_each_item(previous_each_item); tag = next_tag;
}); if (tag) current_tag = tag;
set_should_intro(true);
return () => { set_current_each_item(previous_each_item);
element?.remove();
};
}); });
} }

Loading…
Cancel
Save