Skip to content

Commit

Permalink
Merge de388d2 into 4aa291e
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Sep 25, 2019
2 parents 4aa291e + de388d2 commit 48408fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compat/src/index.js
Expand Up @@ -303,8 +303,8 @@ let classNameDescriptor = {
* @returns {boolean}
*/
function shallowDiffers(a, b) {
for (let i in a) if (!(i in b)) return true;
for (let i in b) if (a[i]!==b[i]) return true;
for (let i in a) if (i !== '__source' && !(i in b)) return true;
for (let i in b) if (i !== '__source' && a[i]!==b[i]) return true;
return false;
}

Expand Down
28 changes: 28 additions & 0 deletions compat/test/browser/component.test.js
Expand Up @@ -95,6 +95,34 @@ describe('components', () => {
expect(spy).to.be.calledWithMatch(expected, expected);
});

it('should ignore the __source variable', () => {
const pureSpy = sinon.spy();
const appSpy = sinon.spy();
let set;
class Pure extends React.PureComponent {
render() {
pureSpy();
return <div>Static</div>;
}
}

const App = () => {
const [, setState] = React.useState(0);
appSpy();
set = setState;
return <Pure __source={{}} />;
};

React.render(<App />, scratch);
expect(appSpy).to.be.calledOnce;
expect(pureSpy).to.be.calledOnce;

set(1);
rerender();
expect(appSpy).to.be.calledTwice;
expect(pureSpy).to.be.calledOnce;
});

it('should only re-render when props or state change', () => {
class C extends React.PureComponent {
render() {
Expand Down

0 comments on commit 48408fd

Please sign in to comment.