Skip to content

Commit

Permalink
Fix stale props reference when sCU returns false
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 7, 2019
1 parent 18d0145 commit 27e4e22
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export function diff(dom, parentDom, newVNode, oldVNode, context, isSvg, excessD
}

if (!c._force && c.shouldComponentUpdate!=null && c.shouldComponentUpdate(newVNode.props, s, cctx)===false) {
c.props = newVNode.props;
c._dirty = false;
break outer;
}
Expand Down
29 changes: 29 additions & 0 deletions test/browser/lifecycle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,35 @@ describe('Lifecycle methods', () => {
expect(nextPropsArg).to.deep.equal({ foo: 'bar' });
expect(nextStateArg).to.deep.equal({ value: 4 });
});

it('should update props reference when sCU reutrns false', () => {
let spy = sinon.spy();

let updateState;
class Foo extends Component {
constructor() {
super();
updateState = () => this.setState({});
}

shouldComponentUpdate(nextProps) {
if (nextProps !== this.props) {
spy();
return false;
}
return true;
}
}

render(<Foo foo="foo" />, scratch);
render(<Foo foo="bar" />, scratch);
expect(spy).to.be.calledOnce;

updateState();
rerender();

expect(spy).to.be.calledOnce;
});
});


Expand Down

0 comments on commit 27e4e22

Please sign in to comment.