-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Warn if unsafe lifecycle methods are found in an async subtree #12060
Conversation
Details of bundled changes.Comparing: 4ca7855...97e2820 react-native-renderer
Generated by 🚫 dangerJS |
Lol, sorry, the detection is a bit wrong. I’m actually surprised why it still runs because I thought I disabled it in 04d8fec. Maybe your PR is based on an earlier commit. |
Note to self for when I'm more awake: Do I need to reset pending warnings in the event of an error or interruption? Or is it okay to just warn on the next complete phrase, since the unsafe methods still exist in the source? May best to explicitly reset when starting a new begin phase just in case? Will want to add a test case for this if so. Edit I think it is okay to still warn in this case. I am open to discussion here though if others disagree. |
Unsafe async warnings are now grouped by their parent async trees (whihc can be identified via component stacks included in the message). We also coalesce warnings and print during the complete phase. Warnings are deduped per component type, after much consideration.
Rebased~ |
This causes too much noise in the log. Also added/hardened tests around this case.
This is based on a suggestion from Jed Watson that the UNSAFE_* prefix in the warning message was a little confusing
Regarding an initial question in the PR description:
I think I picked a safer approach in a1b5f0f, but if this is incorrect, let me know. |
Works like AsyncComponent except that it does not actually enable async rendering. This component is exposed via React.unstable_PreAsyncComponent (following precedent). I also tidied up ReactBaseClass a little because the duplication was bothering me. I will revert this if there's any concern. This branch is stacked on top of 12046-part-2 and PR facebook#12060
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 think we'll need a URL to a more descriptive doc where we can document all the patterns to upgrade to.
// are often vague and are likely to collide between 3rd party libraries. | ||
// An expand property is probably okay to use here since it's DEV-only, | ||
// and will only be set in the event of serious warnings. | ||
if (fiber.type[DID_WARN_KEY] === 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.
We are using a Map in here anyway so why don't we just use a Set for this? (To ensure that it is safe on frozen objects.)
Yes, totally. This is why I used an fb.me link. We can update it once we write a blog post or documentation. |
Works like AsyncComponent except that it does not actually enable async rendering. This component is exposed via React.unstable_PreAsyncComponent (following precedent). I also tidied up ReactBaseClass a little because the duplication was bothering me. I will revert this if there's any concern. This branch is stacked on top of 12046-part-2 and PR facebook#12060
Works like AsyncComponent except that it does not actually enable async rendering. This component is exposed via React.unstable_PreAsyncComponent (following precedent). I also tidied up ReactBaseClass a little because the duplication was bothering me. I will revert this if there's any concern. This branch is stacked on top of 12046-part-2 and PR facebook#12060
Works like AsyncComponent except that it does not actually enable async rendering. This component is exposed via React.unstable_PreAsyncComponent (following precedent). I also tidied up ReactBaseClass a little because the duplication was bothering me. I will revert this if there's any concern. This branch is stacked on top of 12046-part-2 and PR facebook#12060
Builds on top of PR facebook#12083 and resolves issue facebook#12044. Coalesces deprecation warnings until the commit phase. This proposal extends the utility introduced in facebook#12060 to also coalesce deprecation warnings. New warning format will look like this: > componentWillMount is deprecated and will be removed in the next major version. Use componentDidMount instead. As a temporary workaround, you can rename to UNSAFE_componentWillMount. > > Please update the following components: Foo, Bar > > Learn more about this warning here: > https://fb.me/react-async-component-lifecycle-hooks
Builds on top of PR #12083 and resolves issue #12044. Coalesces deprecation warnings until the commit phase. This proposal extends the utility introduced in #12060 to also coalesce deprecation warnings. New warning format will look like this: > componentWillMount is deprecated and will be removed in the next major version. Use componentDidMount instead. As a temporary workaround, you can rename to UNSAFE_componentWillMount. > > Please update the following components: Foo, Bar > > Learn more about this warning here: > https://fb.me/react-async-component-lifecycle-hooks
Part two of #12046
This PR identifies class-components using unsafe lifecycles (
componenWillMount
,componenWillReceiveProps
,componenWillUpdate
) during the begin phase, and prints warnings about them (and with the location of the async subtree they belong to) during the commit phase. In the event of an error, pending warnings are discarded byperformFailedUnitOfWork
.Example warning
A warning for a particular async subtree will look like this:
How are warnings grouped?
I put a lot of consideration into how to group/coalesce the warnings, as well as how to dedup them. I landed on the following:
Alternatives considered
I considered different deduping strategies but this felt the most pragmatic. Other considerations were:
Open Questions
pendingWarningsMap
safe? Are there cases (like interruptions) that it won't handle well? (cc @acdlite)