-
Notifications
You must be signed in to change notification settings - Fork 50.1k
[Fiber] Component lifecycle tests #8949
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] Component lifecycle tests #8949
Conversation
scripts/fiber/tests-failing.txt
Outdated
| src/renderers/shared/shared/__tests__/ReactComponentLifeCycle-test.js | ||
| * should carry through each of the phases of setup | ||
| src/renderers/shared/shared/__tests__/ReactCompositeComponentState-test.js | ||
| * should batch unmounts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops just noticed this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guh. Sorry for missing it.
7e26a90 to
38ecbc1
Compare
| if (typeof instance.componentWillUnmount === 'function') { | ||
| safelyCallComponentWillUnmount(current, instance); | ||
| } | ||
| ReactInstanceMap.remove(instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never safe to rely on unmount.
| }).not.toThrow(); | ||
|
|
||
| // Stack doesn't warn | ||
| if (ReactDOMFeatureFlags.useFiber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
Also, if it doesn't warn, do you think this could create warning noise in codebases that already rely on this pattern? It would be nice to check Power Editor and other React-heavy projects for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My hunch is that setState on an unmounting parent in componentWillUnmount isn't that common but yeah I'll check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changed, moot now anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Life cycle test needs to be replaced by something like isMounted. The instance map is not safe.
38ecbc1 to
617e7d3
Compare
|
@sebmarkbage Updated |
Need to reset current owner to null before committing
|
|
||
| module.exports = function( | ||
| scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel) => void, | ||
| scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel, callerName : string | null) => void, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this pattern since they don't get stripped in prod. Can we reword it to be setState, replaceState or forceUpdate in the message instead of complicating the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm passing null in prod. But yeah, I like that better anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should do the same in ReactFiberUpdateQueue https://github.com/facebook/react/blob/master/src/renderers/shared/fiber/ReactFiberUpdateQueue.js#L217
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea
426acd9 to
c725ed4
Compare
|
@sebmarkbage Updated again |
|
Forgot to update the Stack warnings |
c725ed4 to
e9aca8e
Compare
|
Fixed |
We want to avoid passing around caller names because stripping them out in production complicates the code for little benefit.
sebmarkbage
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to update the whitelists!
| 'componentDidUpdate instead.', | ||
| getComponentName(owner) || 'A component' | ||
| ); | ||
| (owner: any)._warnedAboutRefsInRender = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Should we preventExtensions on fibers? Like we do in Stack instantiate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea. Let's add it in the constructor in DEV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But expandos on the class isn't really better neither.
Fixes tests in ReactComponentLifeCycle-test.js
Biggest change is to set current owner to null at beginning of commit phase.