Reset instance vars before calling commit phase lifecycles#10481
Reset instance vars before calling commit phase lifecycles#10481acdlite merged 1 commit intofacebook:masterfrom
Conversation
sebmarkbage
left a comment
There was a problem hiding this comment.
arguments, slice and apply are all things that are often slow paths. can we do less meta programming and more programming?
dd70c0a to
834938e
Compare
|
@sebmarkbage Updated, now with more programming |
| startPhaseTimer(finishedWork, 'componentDidMount'); | ||
| } | ||
| instance.props = finishedWork.memoizedProps; | ||
| instance.state = finishedWork.memoizedState; |
There was a problem hiding this comment.
Is there any observable way these wouldn't already be the same?
Other than the user setting them themselves? (I suppose if they do, then this is a breaking change now.)
There was a problem hiding this comment.
Not that I can think of, more concerned about the case I can't think of, like how I didn't consider error boundaries. Is this a perf concern?
There was a problem hiding this comment.
I can think of some in async mode, just not sync mode.
There was a problem hiding this comment.
What about async mode? I can't even think of them there.
| startPhaseTimer(finishedWork, 'componentDidUpdate'); | ||
| } | ||
| instance.props = finishedWork.memoizedProps; | ||
| instance.state = finishedWork.memoizedState; |
Fixes an issue where if a component throws, its instance variables are not reset before
componentWillUnmountis called. See https://jsfiddle.net/m3pL3yaj/ for an illustration.To protect against issues like this, we should always set
this.propsandthis.stateright before calling a lifecycle method, as if they were explicit arguments.