Skip to content

Commit

Permalink
fix: diff for referenced nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Oct 4, 2021
1 parent 702eaba commit 1ee38f0
Show file tree
Hide file tree
Showing 5 changed files with 506 additions and 347 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
"devDependencies": {
"@babel/runtime": "^7.14.0",
"@chialab/eslint-config": "^2.0.0",
"@chialab/rna": "^0.11.0",
"@chialab/rna-apidoc": "^0.11.0",
"@chialab/rna-browser-test-runner": "^0.11.0",
"@chialab/rna-bundler": "^0.11.0",
"@chialab/rna-node-test-runner": "^0.11.0",
"@chialab/rna-saucelabs-test-runner": "^0.11.0",
"@chialab/rna": "^0.12.0",
"@chialab/rna-apidoc": "^0.12.0",
"@chialab/rna-browser-test-runner": "^0.12.0",
"@chialab/rna-bundler": "^0.12.0",
"@chialab/rna-node-test-runner": "^0.12.0",
"@chialab/rna-saucelabs-test-runner": "^0.12.0",
"@chialab/semantic-release-config": "^1.0.0",
"@esm-bundle/chai": "^4.3.4",
"@types/jsdom": "^16.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/CustomElementRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ export class CustomElementRegistry {
const nodes = root.children;
// iterate all nodes found
for (let i = 0, len = nodes.length; i < len; i++) {
this.upgrade(nodes[i] as HTMLElement);
const node = nodes[i] as HTMLElement;
if (node) {
this.upgrade(node);
}
}
if (!constructor) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/JSX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ function h(tagOrComponent: typeof Fragment | FunctionComponent | CustomElementCo
if (ref) {
return {
node: ref,
key,
key: ref,
namespaceURI: xmlns,
properties: properties || {},
children,
Expand Down
71 changes: 34 additions & 37 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,52 +361,49 @@ export const internalRender = (
}

const { key, children, namespaceURI } = template;
if (isVNode(template)) {
templateNode = template.node;
} else {
templateNamespace = namespaceURI || namespace;

checkKey: if (currentContext) {
let currentKey = currentContext.key;
if (currentKey != null && key != null && key !== currentKey) {
emptyFragments(currentContext);
DOM.removeChild(root, currentNode, slot);
currentNode = childNodes.item(currentIndex) as Node;
currentContext = currentNode ? getOrCreateContext(currentNode) : null;
if (!currentContext) {
break checkKey;
}
currentKey = currentContext.key;
templateNamespace = namespaceURI || namespace;
checkKey: if (currentContext) {
let currentKey = currentContext.key;
if (currentKey != null && key != null && key !== currentKey) {
emptyFragments(currentContext);
DOM.removeChild(root, currentNode, slot);
currentNode = childNodes.item(currentIndex) as Node;
currentContext = currentNode ? getOrCreateContext(currentNode) : null;
if (!currentContext) {
break checkKey;
}
currentKey = currentContext.key;
}

if (currentFragment && currentNode) {
const io = indexOf.call(childNodes, currentNode);
const lastIo = indexOf.call(childNodes, currentFragment.end);
if (io !== -1 && io > lastIo) {
break checkKey;
}
if (currentFragment && currentNode) {
const io = indexOf.call(childNodes, currentNode);
const lastIo = indexOf.call(childNodes, currentFragment.end);
if (io !== -1 && io > lastIo) {
break checkKey;
}
}

if (key != null || currentKey != null) {
if (key === currentKey) {
templateNode = currentNode;
templateContext = currentContext;
}
} else if (isVComponent(template) && currentNode instanceof template.Component) {
templateNode = currentNode;
templateContext = currentContext;
} else if (isVTag(template) && currentContext.tagName === template.tag) {
if (key != null || currentKey != null) {
if (key === currentKey) {
templateNode = currentNode;
templateContext = currentContext;
}
} else if (isVComponent(template) && currentNode instanceof template.Component) {
templateNode = currentNode;
templateContext = currentContext;
} else if (isVTag(template) && currentContext.tagName === template.tag) {
templateNode = currentNode;
templateContext = currentContext;
}
}

if (!templateNode) {
if (isVComponent(template)) {
templateNode = new template.Component();
} else {
templateNode = DOM.createElementNS(templateNamespace, template.tag);
}
if (!templateNode) {
if (isVNode(template)) {
templateNode = template.node;
} else if (isVComponent(template)) {
templateNode = new template.Component();
} else {
templateNode = DOM.createElementNS(templateNamespace, template.tag);
}
}

Expand Down
Loading

0 comments on commit 1ee38f0

Please sign in to comment.