MCPcopy
hub / github.com/preactjs/preact / diffElementNodes

Function diffElementNodes

src/diff/index.js:411–609  ·  view source on GitHub ↗

* Diff two virtual nodes representing DOM element * @param {PreactElement} dom The DOM element representing the virtual nodes * being diffed * @param {VNode} newVNode The new virtual node * @param {VNode} oldVNode The old virtual node * @param {object} globalContext The current context object

(
	dom,
	newVNode,
	oldVNode,
	globalContext,
	namespace,
	excessDomChildren,
	commitQueue,
	isHydrating,
	refQueue
)

Source from the content-addressed store, hash-verified

409 * @returns {PreactElement}
410 */
411function diffElementNodes(
412 dom,
413 newVNode,
414 oldVNode,
415 globalContext,
416 namespace,
417 excessDomChildren,
418 commitQueue,
419 isHydrating,
420 refQueue
421) {
422 let oldProps = oldVNode.props || EMPTY_OBJ;
423 let newProps = newVNode.props;
424 let nodeType = /** @type {string} */ (newVNode.type);
425 /** @type {any} */
426 let i;
427 /** @type {{ __html?: string }} */
428 let newHtml;
429 /** @type {{ __html?: string }} */
430 let oldHtml;
431 /** @type {ComponentChildren} */
432 let newChildren;
433 let value;
434 let inputValue;
435 let checked;
436
437 // Tracks entering and exiting namespaces when descending through the tree.
438 if (nodeType == 'svg') namespace = SVG_NAMESPACE;
439 else if (nodeType == 'math') namespace = MATH_NAMESPACE;
440 else if (!namespace) namespace = XHTML_NAMESPACE;
441
442 if (excessDomChildren != NULL) {
443 for (i = 0; i < excessDomChildren.length; i++) {
444 value = excessDomChildren[i];
445
446 // if newVNode matches an element in excessDomChildren or the `dom`
447 // argument matches an element in excessDomChildren, remove it from
448 // excessDomChildren so it isn't later removed in diffChildren
449 if (
450 value &&
451 'setAttribute' in value == !!nodeType &&
452 (nodeType ? value.localName == nodeType : value.nodeType == 3)
453 ) {
454 dom = value;
455 excessDomChildren[i] = NULL;
456 break;
457 }
458 }
459 }
460
461 if (dom == NULL) {
462 if (nodeType == NULL) {
463 return document.createTextNode(newProps);
464 }
465
466 dom = document.createElementNS(
467 namespace,
468 nodeType,

Callers 1

diffFunction · 0.85

Calls 5

setPropertyFunction · 0.90
diffChildrenFunction · 0.90
getDomSiblingFunction · 0.90
removeNodeFunction · 0.90
_hydrationMismatchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…