-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
[DevTools] [Context] Legacy Context #16617
Changes from 6 commits
dc78a67
98be5bc
9baac45
bc9d387
fd6914f
b1d3a6c
e409465
afa2f3d
de31745
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 |
---|---|---|
|
@@ -753,6 +753,9 @@ export function attach( | |
// Can view component source location. | ||
canViewSource: type === ElementTypeClass || type === ElementTypeFunction, | ||
|
||
// Only legacy context exists in legacy versions. | ||
hasLegacyContext: true, | ||
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. Should we also hide empty one though in the legacy mode? 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 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 |
||
|
||
displayName: displayName, | ||
|
||
type: type, | ||
|
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,13 @@ export function attach( | |
) { | ||
canViewSource = true; | ||
if (stateNode && stateNode.context != null) { | ||
context = stateNode.context; | ||
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 +2174,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 +2249,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. | ||
|
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.
😆
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.
Freakin' WebStorm 😆 #NeverTrustYourEditor