Skip to content

Commit

Permalink
Merge b973c40 into 9ead713
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jun 10, 2019
2 parents 9ead713 + b973c40 commit 5c33d91
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/diff/index.js
Expand Up @@ -281,7 +281,7 @@ export function unmount(vnode, parentVNode, skipRemove) {
}

let dom;
if (!skipRemove && vnode._lastDomChild==null) {
if (!skipRemove && typeof vnode.type !== 'function') {
skipRemove = (dom = vnode._dom)!=null;
}

Expand Down
86 changes: 86 additions & 0 deletions test/browser/components.test.js
Expand Up @@ -183,6 +183,92 @@ describe('Components', () => {
expect(scratch.innerHTML).to.equal('<div foo="bar">Hello</div>');
});

it('should also update the current dom', () => {
let trigger;

class A extends Component {
constructor(props) {
super(props);
this.state = { show: false };
trigger = this.set = this.set.bind(this);
}

set() {
this.setState({ show: true });
}

render() {
return this.state.show ? <div>A</div> : null;
}
}

const B = () => <p>B</p>;

render(
<div>
<A />
<B />
</div>,
scratch
);
expect(scratch.innerHTML).to.equal('<div><p>B</p></div>');

trigger();
rerender();
expect(scratch.innerHTML).to.equal('<div><div>A</div><p>B</p></div>');
});

it('should not orphan children', () => {
let triggerC, triggerA;
const B = () => <p>B</p>;

// Component with state which swaps its returned element type
class C extends Component {
constructor(props) {
super(props);
this.state = { show: false };
triggerC = this.set = this.set.bind(this);
}

set() {
this.setState({ show: true });
}

render() {
return this.state.show ? <div>data</div> : <p>Loading</p>;
}
}

const WrapC = () => <C />;

class A extends Component {
constructor(props) {
super(props);
this.state = { show: false };
triggerA = this.set = this.set.bind(this);
}

set() {
this.setState({ show: true });
}

render() {
return this.state.show ? <B /> : <WrapC />;
}
}

render(<A />, scratch);
expect(scratch.innerHTML).to.equal('<p>Loading</p>');

triggerC();
rerender();
expect(scratch.innerHTML).to.equal('<div>data</div>');

triggerA();
rerender();
expect(scratch.innerHTML).to.equal('<p>B</p>');
});

it('should render components that don\'t pass args into the Component constructor (unistore pattern)', () => {
// Pattern unistore uses for connect: https://git.io/fxRqu
function Wrapper() {
Expand Down

0 comments on commit 5c33d91

Please sign in to comment.