diff --git a/compat/src/index.js b/compat/src/index.js index 999c8e24f59..2855eb5cfc8 100644 --- a/compat/src/index.js +++ b/compat/src/index.js @@ -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; } diff --git a/compat/test/browser/component.test.js b/compat/test/browser/component.test.js index 95538707e7e..0138067db82 100644 --- a/compat/test/browser/component.test.js +++ b/compat/test/browser/component.test.js @@ -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
Static
; + } + } + + const App = () => { + const [, setState] = React.useState(0); + appSpy(); + set = setState; + return ; + }; + + React.render(, 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() {