-
Notifications
You must be signed in to change notification settings - Fork 49k
[DevTools] [Context] Legacy Context #16617
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
Merged
bvaughn
merged 9 commits into
facebook:master
from
hristo-kanchev:feature/devtools-legacy-context
Sep 10, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dc78a67
Added hasLegacyContext check.
hristo-kanchev 98be5bc
Passed hasLegacyContext as prop to SelectedElement
hristo-kanchev 9baac45
Changing context labels based on hasLegacyContext
hristo-kanchev bc9d387
Fixed flow types.
hristo-kanchev fd6914f
Fixed typos.
hristo-kanchev b1d3a6c
Added tests for hasLegacyContext.
hristo-kanchev e409465
Renamed test.
hristo-kanchev afa2f3d
Removed test imports.
hristo-kanchev de31745
Added inline comment
bvaughn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2107,6 +2107,8 @@ export function attach( | |
type, | ||
} = fiber; | ||
|
||
const elementType = getElementTypeForFiber(fiber); | ||
|
||
const usesHooks = | ||
(tag === FunctionComponent || | ||
tag === SimpleMemoComponent || | ||
|
@@ -2128,7 +2130,14 @@ export function attach( | |
) { | ||
canViewSource = true; | ||
if (stateNode && stateNode.context != null) { | ||
context = stateNode.context; | ||
// Don't show an empty context object for class components that don't use the context API. | ||
const shouldHideContext = | ||
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. This could probably use an explanatory inline comment. (I'll add one.) |
||
elementType === ElementTypeClass && | ||
!(type.contextTypes || type.contextType); | ||
|
||
if (!shouldHideContext) { | ||
context = stateNode.context; | ||
} | ||
} | ||
} else if ( | ||
typeSymbol === CONTEXT_CONSUMER_NUMBER || | ||
|
@@ -2166,7 +2175,10 @@ export function attach( | |
} | ||
} | ||
|
||
let hasLegacyContext = false; | ||
if (context !== null) { | ||
hasLegacyContext = !!type.contextTypes; | ||
|
||
// To simplify hydration and display logic for context, wrap in a value object. | ||
// Otherwise simple values (e.g. strings, booleans) become harder to handle. | ||
context = {value: context}; | ||
|
@@ -2238,8 +2250,11 @@ export function attach( | |
// Can view component source location. | ||
canViewSource, | ||
|
||
// Does the component have legacy context attached to it. | ||
hasLegacyContext, | ||
|
||
displayName: getDisplayNameForFiber(fiber), | ||
type: getElementTypeForFiber(fiber), | ||
type: elementType, | ||
|
||
// Inspectable properties. | ||
// TODO Review sanitization approach for the below inspectable values. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we also hide empty one though in the legacy mode?
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 value isn't used to hide the context label in the front end.. It just specifies whether the context is modern vs legacy. I guess it's a little weird to have a boolean value for this. Maybe we should use an enum? context type: none, modern, legacy.
Anyway, an empty legacy context won't be shown on the frontend because the
InspectedElementTree
component hides itself if the value it's passed is null or an empty object.