Skip to content

Commit

Permalink
Merge pull request #1361 from alibaba/fragment-diff
Browse files Browse the repository at this point in the history
Only prevNativeNode is empty fragment should find the prevSlibingNativeNode
  • Loading branch information
yuanyan authored Sep 17, 2019
2 parents 7120548 + 682f9fc commit 946d1db
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/rax/src/vdom/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,13 @@ class CompositeComponent extends BaseComponent {
});
}
} else {
let lastNativeNode = null;
let prevNativeNode = prevRenderedComponent.__getNativeNode();
// Only prevNativeNode is empty fragment should find the prevSlibingNativeNode
if (isArray(prevNativeNode) && prevNativeNode.length === 0) {
lastNativeNode = getPrevSiblingNativeNode(prevRenderedComponent);
}

prevRenderedComponent.unmountComponent(true);

this[RENDERED_COMPONENT] = instantiateComponent(nextRenderedElement);
Expand All @@ -469,25 +475,16 @@ class CompositeComponent extends BaseComponent {
(newNativeNode, parent) => {
prevNativeNode = toArray(prevNativeNode);
newNativeNode = toArray(newNativeNode);
let isFragmentAsPreNativeNode = isArray(prevNativeNode);

const driver = Host.driver;

// If the new length large then prev
let lastNativeNode;
for (let i = 0; i < newNativeNode.length; i++) {
let nativeNode = newNativeNode[i];
if (prevNativeNode[i]) {
driver.replaceChild(nativeNode, prevNativeNode[i]);
} else if (lastNativeNode) {
driver.insertAfter(nativeNode, lastNativeNode);
} else if (isFragmentAsPreNativeNode && this.__parentInstance) {
let mountedNode = getPrevSiblingNativeNode(this);
if (mountedNode) {
driver.insertAfter(nativeNode, mountedNode, parent);
} else {
driver.appendChild(nativeNode, parent);
}
} else {
driver.appendChild(nativeNode, parent);
}
Expand Down

0 comments on commit 946d1db

Please # to comment.