Skip to content

Commit

Permalink
fix: when prev fragment is empty and update to other type
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyan committed Sep 17, 2019
1 parent 3758da3 commit 894e44e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/rax/src/vdom/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export default class NativeComponent extends BaseComponent {
let isFragmentParent = isArray(parent);
let prevFirstChild = null;
let prevFirstNativeNode = null;
let isPrevFirstEmptyFragment = false;
let shouldUnmountPrevFirstChild = false;
let lastPlacedNode = null;

Expand All @@ -364,17 +365,20 @@ export default class NativeComponent extends BaseComponent {
prevFirstNativeNode = prevFirstChild.__getNativeNode();

if (isArray(prevFirstNativeNode)) {
isPrevFirstEmptyFragment = prevFirstNativeNode.length === 0;
prevFirstNativeNode = prevFirstNativeNode[0];
}
} else if (shouldUnmount) {
prevChild.unmountComponent(shouldRemoveAllChildren);
}
}

// When fragment embed fragment updated but prev fragment is empty
// 1. When fragment embed fragment updated but prev fragment is empty
// that need to get the prev sibling native node.
// like: [ [] ] -> [ [1, 2] ]
if (isFragmentParent && parent.length === 0 ) {
// 2. When prev fragment is empty and update to other type
// like: [ [], 1 ] -> [ 1, 2 ]
if (isFragmentParent && parent.length === 0 || isPrevFirstEmptyFragment) {
lastPlacedNode = getPrevSiblingNativeNode(this);
}
}
Expand Down

0 comments on commit 894e44e

Please sign in to comment.