-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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] Support secondary environment name when it changes #30842
Changes from all commits
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* @flow | ||
*/ | ||
|
||
import type {ReactComponentInfo} from 'shared/ReactTypes'; | ||
import type {ReactComponentInfo, ReactDebugInfo} from 'shared/ReactTypes'; | ||
|
||
import { | ||
ComponentFilterDisplayName, | ||
|
@@ -2207,6 +2207,7 @@ export function attach( | |
function recordVirtualMount( | ||
instance: VirtualInstance, | ||
parentInstance: DevToolsInstance | null, | ||
secondaryEnv: null | string, | ||
): void { | ||
const id = instance.id; | ||
|
||
|
@@ -2220,6 +2221,9 @@ export function attach( | |
let displayName = componentInfo.name || ''; | ||
if (typeof env === 'string') { | ||
// We model environment as an HoC name for now. | ||
if (secondaryEnv !== null) { | ||
displayName = secondaryEnv + '(' + displayName + ')'; | ||
} | ||
displayName = env + '(' + displayName + ')'; | ||
} | ||
const elementType = ElementTypeVirtual; | ||
|
@@ -2419,6 +2423,25 @@ export function attach( | |
pendingRealUnmountedIDs.push(id); | ||
} | ||
|
||
function getSecondaryEnvironmentName( | ||
debugInfo: ?ReactDebugInfo, | ||
index: number, | ||
): null | string { | ||
if (debugInfo != null) { | ||
const componentInfo: ReactComponentInfo = (debugInfo[index]: any); | ||
for (let i = index + 1; i < debugInfo.length; i++) { | ||
const debugEntry = debugInfo[i]; | ||
if (typeof debugEntry.env === 'string') { | ||
// If the next environment is different then this component was the boundary | ||
// and it changed before entering the next component. So we assign this | ||
// component a secondary environment. | ||
return componentInfo.env !== debugEntry.env ? debugEntry.env : null; | ||
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. What if 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. There's no instances here. This is just walking the debugInfo array and comparing it to other entires in that array.
However, I don't actually use the secondary environment later on if the first one isn't specified. I assume that then it was just a client component or something that was inlined. But that case doesn't really exist yet. |
||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
function mountVirtualChildrenRecursively( | ||
firstChild: Fiber, | ||
lastChild: null | Fiber, // non-inclusive | ||
|
@@ -2439,6 +2462,7 @@ export function attach( | |
// Not a Component. Some other Debug Info. | ||
continue; | ||
} | ||
// Scan up until the next Component to see if this component changed environment. | ||
const componentInfo: ReactComponentInfo = (debugEntry: any); | ||
if (level === virtualLevel) { | ||
if ( | ||
|
@@ -2458,7 +2482,15 @@ export function attach( | |
); | ||
} | ||
previousVirtualInstance = createVirtualInstance(componentInfo); | ||
recordVirtualMount(previousVirtualInstance, reconcilingParent); | ||
const secondaryEnv = getSecondaryEnvironmentName( | ||
fiber._debugInfo, | ||
i, | ||
); | ||
recordVirtualMount( | ||
previousVirtualInstance, | ||
reconcilingParent, | ||
secondaryEnv, | ||
); | ||
insertChild(previousVirtualInstance); | ||
previousVirtualInstanceFirstFiber = fiber; | ||
} | ||
|
@@ -2914,7 +2946,15 @@ export function attach( | |
} else { | ||
// Otherwise we create a new instance. | ||
const newVirtualInstance = createVirtualInstance(componentInfo); | ||
recordVirtualMount(newVirtualInstance, reconcilingParent); | ||
const secondaryEnv = getSecondaryEnvironmentName( | ||
nextChild._debugInfo, | ||
i, | ||
); | ||
recordVirtualMount( | ||
newVirtualInstance, | ||
reconcilingParent, | ||
secondaryEnv, | ||
); | ||
insertChild(newVirtualInstance); | ||
previousVirtualInstance = newVirtualInstance; | ||
previousVirtualInstanceWasMount = true; | ||
|
This comment was marked as off-topic.
Sorry, something went wrong.