manual cleanup of dom.js

pull/8569/head
Simon Holthausen 3 years ago
parent 67bcdc6df8
commit 00912f2e01

@ -1,17 +1,19 @@
import { ResizeObserverSingleton } from './ResizeObserverSingleton.js'; import { ResizeObserverSingleton } from './ResizeObserverSingleton.js';
import { contenteditable_truthy_values, has_prop } from './utils'; import { contenteditable_truthy_values, has_prop } from './utils.js';
// Track which nodes are claimed during hydration. Unclaimed nodes can then be removed from the DOM // Track which nodes are claimed during hydration. Unclaimed nodes can then be removed from the DOM
// at the end of hydration without touching the remaining nodes. // at the end of hydration without touching the remaining nodes.
let is_hydrating = false; let is_hydrating = false;
/** /**
* @returns {void} */ * @returns {void}
*/
export function start_hydrating() { export function start_hydrating() {
is_hydrating = true; is_hydrating = true;
} }
/** /**
* @returns {void} */ * @returns {void}
*/
export function end_hydrating() { export function end_hydrating() {
is_hydrating = false; is_hydrating = false;
} }
@ -46,7 +48,8 @@ function init_hydrate(target) {
// We know that all children have claim_order values since the unclaimed have been detached if target is not <head> // We know that all children have claim_order values since the unclaimed have been detached if target is not <head>
/** /**
* @type {ArrayLike<NodeEx2>} */ * @type {ArrayLike<NodeEx2>}
*/
let children = target.childNodes; let children = target.childNodes;
// If target is <head>, there may be children without claim_order // If target is <head>, there may be children without claim_order
if (target.nodeName === 'HEAD') { if (target.nodeName === 'HEAD') {
@ -100,12 +103,14 @@ function init_hydrate(target) {
// The longest increasing subsequence of nodes (initially reversed) // The longest increasing subsequence of nodes (initially reversed)
/** /**
* @type {NodeEx2[]} */ * @type {NodeEx2[]}
*/
const lis = []; const lis = [];
// The rest of the nodes, nodes that will be moved // The rest of the nodes, nodes that will be moved
/** /**
* @type {NodeEx2[]} */ * @type {NodeEx2[]}
*/
const toMove = []; const toMove = [];
let last = children.length - 1; let last = children.length - 1;
for (let cur = m[longest] + 1; cur != 0; cur = p[cur - 1]) { for (let cur = m[longest] + 1; cur != 0; cur = p[cur - 1]) {
@ -1187,7 +1192,11 @@ export function construct_svelte_component(component, props) {
* childNodes: NodeListOf<NodeEx>; * childNodes: NodeListOf<NodeEx>;
* }} NodeEx * }} NodeEx
*/ */
/** @typedef {ChildNode & NodeEx} ChildNodeEx */ /** @typedef {ChildNode & NodeEx} ChildNodeEx */
/** @typedef {NodeEx & { claim_order: number }} NodeEx2 */
/** /**
* @typedef {ChildNodeEx[] & { * @typedef {ChildNodeEx[] & {
* claim_info?: { * claim_info?: {

Loading…
Cancel
Save