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

Call refs and lifecycles on indeterminate components #8614

Merged
merged 1 commit into from
Dec 21, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ src/renderers/shared/shared/__tests__/ReactComponentLifeCycle-test.js
* should not throw when updating an auxiliary component
* should allow state updates in componentDidMount
* should call nested lifecycle methods in the right order
* calls effects on module-pattern component

src/renderers/shared/shared/__tests__/ReactCompositeComponent-test.js
* should support module pattern components
Expand Down
10 changes: 6 additions & 4 deletions src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ module.exports = function<T, P, I, TI, C, CX>(
} else {
shouldUpdate = updateClassInstance(current, workInProgress, priorityLevel);
}
return finishClassComponent(current, workInProgress, shouldUpdate);
}

function finishClassComponent(current : ?Fiber, workInProgress : Fiber, shouldUpdate : boolean) {
// Schedule side-effects
if (shouldUpdate) {
workInProgress.effectTag |= Update;
Expand Down Expand Up @@ -335,14 +338,13 @@ module.exports = function<T, P, I, TI, C, CX>(
workInProgress.tag = ClassComponent;
adoptClassInstance(workInProgress, value);
mountClassInstance(workInProgress, priorityLevel);
ReactCurrentOwner.current = workInProgress;
value = value.render();
return finishClassComponent(current, workInProgress, true);
} else {
// Proceed under the assumption that this is a functional component
workInProgress.tag = FunctionalComponent;
reconcileChildren(current, workInProgress, value);
return workInProgress.child;
}
reconcileChildren(current, workInProgress, value);
return workInProgress.child;
}

function updateCoroutineComponent(current, workInProgress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,4 +594,55 @@ describe('ReactComponentLifeCycle', () => {
'inner componentWillUnmount',
]);
});

it('calls effects on module-pattern component', function() {
const log = [];

function Parent() {
return {
render() {
expect(typeof this.props).toBe('object');
log.push('render');
return <Child />;
},
componentWillMount() {
log.push('will mount');
},
componentDidMount() {
log.push('did mount');
},
componentDidUpdate() {
log.push('did update');
},
getChildContext() {
return {x: 2};
},
};
}
Parent.childContextTypes = {
x: React.PropTypes.number,
};
function Child(props, context) {
expect(context.x).toBe(2);
return <div />;
}
Child.contextTypes = {
x: React.PropTypes.number,
};

const div = document.createElement('div');
ReactDOM.render(<Parent ref={(c) => c && log.push('ref')} />, div);
ReactDOM.render(<Parent ref={(c) => c && log.push('ref')} />, div);

expect(log).toEqual([
'will mount',
'render',
'did mount',
'ref',

'render',
'did update',
'ref',
]);
});
});