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] Component lifecycle tests #8949

Merged
merged 5 commits into from
Feb 22, 2017

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Feb 7, 2017

Fixes tests in ReactComponentLifeCycle-test.js

Biggest change is to set current owner to null at beginning of commit phase.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops just noticed this

Copy link
Contributor

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.

@acdlite acdlite force-pushed the fibercomponentlifecycletests branch 2 times, most recently from 7e26a90 to 38ecbc1 Compare February 7, 2017 22:57
@@ -343,6 +344,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
if (typeof instance.componentWillUnmount === 'function') {
safelyCallComponentWillUnmount(current, instance);
}
ReactInstanceMap.remove(instance);
Copy link
Collaborator

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.

@@ -345,6 +349,15 @@ describe('ReactCompositeComponent-state', () => {
expect(() => {
ReactDOM.unmountComponentAtNode(container);
}).not.toThrow();

// Stack doesn't warn
if (ReactDOMFeatureFlags.useFiber) {
Copy link
Collaborator

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.

Copy link
Collaborator Author

@acdlite acdlite Feb 7, 2017

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

Copy link
Collaborator Author

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

Copy link
Collaborator

@sebmarkbage sebmarkbage left a 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.

@acdlite acdlite force-pushed the fibercomponentlifecycletests branch from 38ecbc1 to 617e7d3 Compare February 8, 2017 00:51
@acdlite
Copy link
Collaborator Author

acdlite commented Feb 8, 2017

@sebmarkbage Updated

@@ -41,7 +41,7 @@ var invariant = require('invariant');
const isArray = Array.isArray;

module.exports = function(
scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel) => void,
scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel, callerName : string | null) => void,
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea

@acdlite acdlite force-pushed the fibercomponentlifecycletests branch 2 times, most recently from 426acd9 to c725ed4 Compare February 8, 2017 19:03
@acdlite
Copy link
Collaborator Author

acdlite commented Feb 8, 2017

@sebmarkbage Updated again

@acdlite
Copy link
Collaborator Author

acdlite commented Feb 8, 2017

Forgot to update the Stack warnings

@acdlite acdlite force-pushed the fibercomponentlifecycletests branch from c725ed4 to e9aca8e Compare February 8, 2017 19:24
@acdlite
Copy link
Collaborator Author

acdlite commented Feb 8, 2017

Fixed

We want to avoid passing around caller names because stripping them
out in production complicates the code for little benefit.
Copy link
Collaborator

@sebmarkbage sebmarkbage left a 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!

@acdlite acdlite merged commit 2081a00 into facebook:master Feb 22, 2017
'%s is accessing findDOMNode inside its render(). ' +
'render() should be a pure function of props and state. It should ' +
'never access something that requires stale data from the previous ' +
'render, such as refs. Move this logic to componentDidMount and ' +
'componentDidUpdate instead.',
getComponentName(owner) || 'A component'
);
(owner: any)._warnedAboutRefsInRender = true;
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants