-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Opt into unsafe lifecycle warnings without async tree #12083
Changes from 9 commits
2b373cb
1ce11f0
0380b50
a98a09a
c0f4e7f
67aec16
f225b46
86cb020
747065b
a0d0551
4a46a30
be6f370
aef6692
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,34 +117,32 @@ if (__DEV__) { | |
} | ||
} | ||
|
||
function ComponentDummy() {} | ||
ComponentDummy.prototype = Component.prototype; | ||
|
||
/** | ||
* Base class helpers for the updating state of a component. | ||
* Convenience component with default shallow equality check for sCU. | ||
*/ | ||
function PureComponent(props, context, updater) { | ||
// Duplicated from Component. | ||
this.props = props; | ||
this.context = context; | ||
this.refs = emptyObject; | ||
// We initialize the default updater but the real one gets injected by the | ||
// renderer. | ||
this.updater = updater || ReactNoopUpdateQueue; | ||
} | ||
|
||
function ComponentDummy() {} | ||
ComponentDummy.prototype = Component.prototype; | ||
const pureComponentPrototype = (PureComponent.prototype = new ComponentDummy()); | ||
pureComponentPrototype.constructor = PureComponent; | ||
// Avoid an extra prototype jump for these methods. | ||
Object.assign(pureComponentPrototype, Component.prototype); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this matters these days in any significant way? Maybe we can just kill this. |
||
pureComponentPrototype.isPureReactComponent = true; | ||
|
||
/** | ||
* Special component type that opts subtree into async rendering mode. | ||
*/ | ||
function AsyncComponent(props, context, updater) { | ||
// Duplicated from Component. | ||
this.props = props; | ||
this.context = context; | ||
this.refs = emptyObject; | ||
// We initialize the default updater but the real one gets injected by the | ||
// renderer. | ||
this.updater = updater || ReactNoopUpdateQueue; | ||
} | ||
|
||
|
@@ -153,8 +151,30 @@ asyncComponentPrototype.constructor = AsyncComponent; | |
// Avoid an extra prototype jump for these methods. | ||
Object.assign(asyncComponentPrototype, Component.prototype); | ||
asyncComponentPrototype.unstable_isAsyncReactComponent = true; | ||
asyncComponentPrototype.__reactStrictMode = true; | ||
asyncComponentPrototype.render = function() { | ||
return this.props.children; | ||
}; | ||
|
||
export {Component, PureComponent, AsyncComponent}; | ||
/** | ||
* Special component type that enables forward-looking, advanced warnings. | ||
* For examples, it detects async-unsafe lifecycles (without actually enabling async mode). | ||
* It can also detect render-phase side effects by double-invoking certain methods. | ||
*/ | ||
function StrictMode(props, context, updater) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this was the silly oversight ;) |
||
this.props = props; | ||
this.context = context; | ||
this.refs = emptyObject; | ||
this.updater = updater || ReactNoopUpdateQueue; | ||
} | ||
|
||
const strictModePrototype = (StrictMode.prototype = new ComponentDummy()); | ||
strictModePrototype.constructor = StrictMode; | ||
// Avoid an extra prototype jump for these methods. | ||
Object.assign(strictModePrototype, Component.prototype); | ||
strictModePrototype.__reactStrictMode = true; | ||
strictModePrototype.render = function() { | ||
return this.props.children; | ||
}; | ||
|
||
export {AsyncComponent, Component, PureComponent, StrictMode}; |
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.
This seems like it is not necessary anymore.