Skip to content

Commit

Permalink
fix: patch up dom diffing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Feb 11, 2023
1 parent e6d4ea3 commit c5f901b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 36 deletions.
15 changes: 4 additions & 11 deletions client/dist/ui.cjs.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/ui.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/ui.cjs.production.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/ui.cjs.production.min.js.map

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions client/dist/ui.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/ui.esm.js.map

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions client/src/engine/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default class Dom {
const newNodes = Array.prototype.slice.call(newNode.children);
const oldNodes = Array.prototype.slice.call(oldNode.children);

console.log('diffing elements', newNodes, oldNodes);

/**
* Get the type for a node
* @param {Node} node The node
Expand Down Expand Up @@ -44,14 +46,14 @@ export default class Dom {
for (let index = 0; index < newNodes.length; index++) {
const node = newNodes[index];

console.log('diffing node', node);
console.log('diffing node', newNodes[index], oldNodes[index], index);

if (!oldNodes[index]) {
const newNodeClone = node.cloneNode(true);
oldNode.appendChild(newNodeClone);
console.log('adding new UI node', newNodeClone);
initComponent(newNodeClone);
return;
continue;
}

if (node instanceof HTMLScriptElement && oldNodes[index] instanceof HTMLScriptElement) {
Expand All @@ -64,11 +66,6 @@ export default class Dom {
newNodeClone,
oldNodes[index]
);
console.log(
'replacing script UI node',
newNodeClone,
oldNodes[index]
);
}

continue;
Expand All @@ -85,7 +82,6 @@ export default class Dom {
) &&
oldNodes[index]?.innerHTML === node.innerHTML
) {
console.log('no changes to UI node', oldNodes[index]);
continue;
}

Expand Down Expand Up @@ -125,7 +121,6 @@ export default class Dom {
newNodeClone,
oldNodes[index]
);
console.log('replacing directive UI node', newNodeClone, oldNodes[index]);
initComponent(newNodeClone);
}

Expand All @@ -152,7 +147,7 @@ export default class Dom {
);
console.log('replacing node', newNodeClone, oldNodes[index]);
initComponent(newNodeClone);
return;
continue;
}

// If content is different, update it
Expand Down

0 comments on commit c5f901b

Please sign in to comment.