Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fiber] fix ensure class components refs get re-assigned to emptyObject on mount #9045

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ src/renderers/__tests__/ReactPerf-test.js
* should not count time in a portal towards lifecycle method
* should work when measurement starts during reconciliation

src/renderers/__tests__/refs-test.js
* Should increase refs with an increase in divs

src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
* gives source code refs for unknown prop warning (ssr)
* gives source code refs for unknown prop warning for exact elements (ssr)
Expand Down
2 changes: 2 additions & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ src/renderers/__tests__/refs-destruction-test.js
* should not error when destroying child with ref asynchronously

src/renderers/__tests__/refs-test.js
* Should increase refs with an increase in divs
* Should correctly get the ref
* Allow refs to hop around children correctly
* always has a value for this.refs
* ref called correctly for stateless component when __DEV__ = false
Expand Down
15 changes: 13 additions & 2 deletions src/renderers/__tests__/refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,23 @@ describe('reactiverefs', () => {
// Now reset again
ReactTestUtils.Simulate.click(testRefsComponent.refs.resetDiv);
expectClickLogsLengthToBe(testRefsComponent, 1);

});

});

describe('factory components', () => {
it('Should correctly get the ref', () => {
function Comp() {
return {
render() {
return <div ref="elemRef" />;
},
};
}

const inst = ReactTestUtils.renderIntoDocument(<Comp />);
expect(inst.refs.elemRef.tagName).toBe('DIV');
});
});

/**
* Tests that when a ref hops around children, we can track that correctly.
Expand Down
1 change: 1 addition & 0 deletions src/renderers/shared/fiber/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ module.exports = function(

instance.props = props;
instance.state = state;
instance.refs = emptyObject;
instance.context = getMaskedContext(workInProgress, unmaskedContext);

if (typeof instance.componentWillMount === 'function') {
Expand Down