GeezerVison is showing github.com — Since debugOwner can now be a non-Fiber, fix up places that assumes i… · react/react@92b9006
File treeExpand file treeCollapse file tree Open diff view settings react-devtools-shared/src/backend react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js +5-17Lines changed: 5 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,10 +33,7 @@ import { | 33 | 33 | import {disableLogs, reenableLogs} from './DevToolsConsolePatching'; | 34 | 34 |
| 35 | 35 | let prefix; | 36 | | -export function describeBuiltInComponentFrame( | 37 | | - name: string, | 38 | | - ownerFn: void | null | Function, | 39 | | -): string { | | 36 | +export function describeBuiltInComponentFrame(name: string): string { | 40 | 37 | if (prefix === undefined) { | 41 | 38 | // Extract the VM specific prefix used by each line. | 42 | 39 | try { | @@ -51,10 +48,7 @@ export function describeBuiltInComponentFrame( | 51 | 48 | } | 52 | 49 |
| 53 | 50 | export function describeDebugInfoFrame(name: string, env: ?string): string { | 54 | | - return describeBuiltInComponentFrame( | 55 | | - name + (env ? ' (' + env + ')' : ''), | 56 | | - null, | 57 | | - ); | | 51 | + return describeBuiltInComponentFrame(name + (env ? ' (' + env + ')' : '')); | 58 | 52 | } | 59 | 53 |
| 60 | 54 | let reentry = false; | @@ -292,15 +286,13 @@ export function describeNativeComponentFrame( | 292 | 286 |
| 293 | 287 | export function describeClassComponentFrame( | 294 | 288 | ctor: Function, | 295 | | - ownerFn: void | null | Function, | 296 | 289 | currentDispatcherRef: CurrentDispatcherRef, | 297 | 290 | ): string { | 298 | 291 | return describeNativeComponentFrame(ctor, true, currentDispatcherRef); | 299 | 292 | } | 300 | 293 |
| 301 | 294 | export function describeFunctionComponentFrame( | 302 | 295 | fn: Function, | 303 | | - ownerFn: void | null | Function, | 304 | 296 | currentDispatcherRef: CurrentDispatcherRef, | 305 | 297 | ): string { | 306 | 298 | return describeNativeComponentFrame(fn, false, currentDispatcherRef); | @@ -313,7 +305,6 @@ function shouldConstruct(Component: Function) { | 313 | 305 |
| 314 | 306 | export function describeUnknownElementTypeFrameInDEV( | 315 | 307 | type: any, | 316 | | - ownerFn: void | null | Function, | 317 | 308 | currentDispatcherRef: CurrentDispatcherRef, | 318 | 309 | ): string { | 319 | 310 | if (!__DEV__) { | @@ -330,31 +321,29 @@ export function describeUnknownElementTypeFrameInDEV( | 330 | 321 | ); | 331 | 322 | } | 332 | 323 | if (typeof type === 'string') { | 333 | | - return describeBuiltInComponentFrame(type, ownerFn); | | 324 | + return describeBuiltInComponentFrame(type); | 334 | 325 | } | 335 | 326 | switch (type) { | 336 | 327 | case SUSPENSE_NUMBER: | 337 | 328 | case SUSPENSE_SYMBOL_STRING: | 338 | | - return describeBuiltInComponentFrame('Suspense', ownerFn); | | 329 | + return describeBuiltInComponentFrame('Suspense'); | 339 | 330 | case SUSPENSE_LIST_NUMBER: | 340 | 331 | case SUSPENSE_LIST_SYMBOL_STRING: | 341 | | - return describeBuiltInComponentFrame('SuspenseList', ownerFn); | | 332 | + return describeBuiltInComponentFrame('SuspenseList'); | 342 | 333 | } | 343 | 334 | if (typeof type === 'object') { | 344 | 335 | switch (type.$$typeof) { | 345 | 336 | case FORWARD_REF_NUMBER: | 346 | 337 | case FORWARD_REF_SYMBOL_STRING: | 347 | 338 | return describeFunctionComponentFrame( | 348 | 339 | type.render, | 349 | | - ownerFn, | 350 | 340 | currentDispatcherRef, | 351 | 341 | ); | 352 | 342 | case MEMO_NUMBER: | 353 | 343 | case MEMO_SYMBOL_STRING: | 354 | 344 | // Memo may contain any component type so we recursively resolve it. | 355 | 345 | return describeUnknownElementTypeFrameInDEV( | 356 | 346 | type.type, | 357 | | - ownerFn, | 358 | 347 | currentDispatcherRef, | 359 | 348 | ); | 360 | 349 | case LAZY_NUMBER: | @@ -366,7 +355,6 @@ export function describeUnknownElementTypeFrameInDEV( | 366 | 355 | // Lazy may contain any component type so we recursively resolve it. | 367 | 356 | return describeUnknownElementTypeFrameInDEV( | 368 | 357 | init(payload), | 369 | | - ownerFn, | 370 | 358 | currentDispatcherRef, | 371 | 359 | ); | 372 | 360 | } catch (x) {} | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/DevToolsFiberComponentStack.js +4-12Lines changed: 4 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,38 +39,30 @@ export function describeFiber( | 39 | 39 | ClassComponent, | 40 | 40 | } = workTagMap; | 41 | 41 |
| 42 | | - const owner: null | Function = __DEV__ | 43 | | - ? workInProgress._debugOwner | 44 | | - ? workInProgress._debugOwner.type | 45 | | - : null | 46 | | - : null; | 47 | 42 | switch (workInProgress.tag) { | 48 | 43 | case HostComponent: | 49 | | - return describeBuiltInComponentFrame(workInProgress.type, owner); | | 44 | + return describeBuiltInComponentFrame(workInProgress.type); | 50 | 45 | case LazyComponent: | 51 | | - return describeBuiltInComponentFrame('Lazy', owner); | | 46 | + return describeBuiltInComponentFrame('Lazy'); | 52 | 47 | case SuspenseComponent: | 53 | | - return describeBuiltInComponentFrame('Suspense', owner); | | 48 | + return describeBuiltInComponentFrame('Suspense'); | 54 | 49 | case SuspenseListComponent: | 55 | | - return describeBuiltInComponentFrame('SuspenseList', owner); | | 50 | + return describeBuiltInComponentFrame('SuspenseList'); | 56 | 51 | case FunctionComponent: | 57 | 52 | case IndeterminateComponent: | 58 | 53 | case SimpleMemoComponent: | 59 | 54 | return describeFunctionComponentFrame( | 60 | 55 | workInProgress.type, | 61 | | - owner, | 62 | 56 | currentDispatcherRef, | 63 | 57 | ); | 64 | 58 | case ForwardRef: | 65 | 59 | return describeFunctionComponentFrame( | 66 | 60 | workInProgress.type.render, | 67 | | - owner, | 68 | 61 | currentDispatcherRef, | 69 | 62 | ); | 70 | 63 | case ClassComponent: | 71 | 64 | return describeClassComponentFrame( | 72 | 65 | workInProgress.type, | 73 | | - owner, | 74 | 66 | currentDispatcherRef, | 75 | 67 | ); | 76 | 68 | default: | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/renderer.js +35-18Lines changed: 35 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1952,15 +1952,24 @@ export function attach( | 1952 | 1952 | const {key} = fiber; | 1953 | 1953 | const displayName = getDisplayNameForFiber(fiber); | 1954 | 1954 | const elementType = getElementTypeForFiber(fiber); | 1955 | | - const {_debugOwner} = fiber; | | 1955 | + const debugOwner = fiber._debugOwner; | 1956 | 1956 |
| 1957 | 1957 | // Ideally we should call getFiberIDThrows() for _debugOwner, | 1958 | 1958 | // since owners are almost always higher in the tree (and so have already been processed), | 1959 | 1959 | // but in some (rare) instances reported in open source, a descendant mounts before an owner. | 1960 | 1960 | // Since this is a DEV only field it's probably okay to also just lazily generate and ID here if needed. | 1961 | 1961 | // See https://github.com/facebook/react/issues/21445 | 1962 | | - const ownerID = | 1963 | | - _debugOwner != null ? getOrGenerateFiberID(_debugOwner) : 0; | | 1962 | + let ownerID: number; | | 1963 | + if (debugOwner != null) { | | 1964 | + if (typeof debugOwner.tag === 'number') { | | 1965 | + ownerID = getOrGenerateFiberID((debugOwner: any)); | | 1966 | + } else { | | 1967 | + // TODO: Track Server Component Owners. | | 1968 | + ownerID = 0; | | 1969 | + } | | 1970 | + } else { | | 1971 | + ownerID = 0; | | 1972 | + } | 1964 | 1973 | const parentID = parentFiber ? getFiberIDThrows(parentFiber) : 0; | 1965 | 1974 |
| 1966 | 1975 | const displayNameStringID = getStringID(displayName); | @@ -3104,15 +3113,17 @@ export function attach( | 3104 | 3113 | return null; | 3105 | 3114 | } | 3106 | 3115 |
| 3107 | | - const {_debugOwner} = fiber; | 3108 | | - | 3109 | 3116 | const owners: Array<SerializedElement> = [fiberToSerializedElement(fiber)]; | 3110 | 3117 |
| 3111 | | - if (_debugOwner) { | 3112 | | - let owner: null | Fiber = _debugOwner; | 3113 | | - while (owner !== null) { | 3114 | | - owners.unshift(fiberToSerializedElement(owner)); | 3115 | | - owner = owner._debugOwner || null; | | 3118 | + let owner = fiber._debugOwner; | | 3119 | + while (owner != null) { | | 3120 | + if (typeof owner.tag === 'number') { | | 3121 | + const ownerFiber: Fiber = (owner: any); // Refined | | 3122 | + owners.unshift(fiberToSerializedElement(ownerFiber)); | | 3123 | + owner = ownerFiber._debugOwner; | | 3124 | + } else { | | 3125 | + // TODO: Track Server Component Owners. | | 3126 | + break; | 3116 | 3127 | } | 3117 | 3128 | } | 3118 | 3129 |
| @@ -3173,7 +3184,7 @@ export function attach( | 3173 | 3184 | } | 3174 | 3185 |
| 3175 | 3186 | const { | 3176 | | - _debugOwner, | | 3187 | + _debugOwner: debugOwner, | 3177 | 3188 | stateNode, | 3178 | 3189 | key, | 3179 | 3190 | memoizedProps, | @@ -3300,13 +3311,19 @@ export function attach( | 3300 | 3311 | context = {value: context}; | 3301 | 3312 | } | 3302 | 3313 |
| 3303 | | - let owners = null; | 3304 | | - if (_debugOwner) { | 3305 | | - owners = ([]: Array<SerializedElement>); | 3306 | | - let owner: null | Fiber = _debugOwner; | 3307 | | - while (owner !== null) { | 3308 | | - owners.push(fiberToSerializedElement(owner)); | 3309 | | - owner = owner._debugOwner || null; | | 3314 | + let owners: null | Array<SerializedElement> = null; | | 3315 | + let owner = debugOwner; | | 3316 | + while (owner != null) { | | 3317 | + if (typeof owner.tag === 'number') { | | 3318 | + const ownerFiber: Fiber = (owner: any); // Refined | | 3319 | + if (owners === null) { | | 3320 | + owners = []; | | 3321 | + } | | 3322 | + owners.unshift(fiberToSerializedElement(ownerFiber)); | | 3323 | + owner = ownerFiber._debugOwner; | | 3324 | + } else { | | 3325 | + // TODO: Track Server Component Owners. | | 3326 | + break; | 3310 | 3327 | } | 3311 | 3328 | } | 3312 | 3329 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeFiberInspector.js +19-8Lines changed: 19 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| | 10 | +import type {ReactComponentInfo} from 'shared/ReactTypes'; | 10 | 11 | import type {Fiber} from 'react-reconciler/src/ReactInternalTypes'; | 11 | 12 | import type {TouchedViewDataAtPoint, InspectorData} from './ReactNativeTypes'; | 12 | 13 |
| @@ -103,13 +104,21 @@ function getInspectorDataForInstance( | 103 | 104 | } | 104 | 105 |
| 105 | 106 | const fiber = findCurrentFiberUsingSlowPath(closestInstance); | | 107 | + if (fiber === null) { | | 108 | + // Might not be currently mounted. | | 109 | + return { | | 110 | + hierarchy: [], | | 111 | + props: emptyObject, | | 112 | + selectedIndex: null, | | 113 | + componentStack: '', | | 114 | + }; | | 115 | + } | 106 | 116 | const fiberHierarchy = getOwnerHierarchy(fiber); | 107 | 117 | const instance = lastNonHostInstance(fiberHierarchy); | 108 | 118 | const hierarchy = createHierarchy(fiberHierarchy); | 109 | 119 | const props = getHostProps(instance); | 110 | 120 | const selectedIndex = fiberHierarchy.indexOf(instance); | 111 | | - const componentStack = | 112 | | - fiber !== null ? getStackByFiberInDevAndProd(fiber) : ''; | | 121 | + const componentStack = getStackByFiberInDevAndProd(fiber); | 113 | 122 |
| 114 | 123 | return { | 115 | 124 | closestInstance: instance, | @@ -125,7 +134,7 @@ function getInspectorDataForInstance( | 125 | 134 | ); | 126 | 135 | } | 127 | 136 |
| 128 | | -function getOwnerHierarchy(instance: any) { | | 137 | +function getOwnerHierarchy(instance: Fiber) { | 129 | 138 | const hierarchy: Array<$FlowFixMe> = []; | 130 | 139 | traverseOwnerTreeUp(hierarchy, instance); | 131 | 140 | return hierarchy; | @@ -143,15 +152,17 @@ function lastNonHostInstance(hierarchy) { | 143 | 152 | return hierarchy[0]; | 144 | 153 | } | 145 | 154 |
| 146 | | -// $FlowFixMe[missing-local-annot] | 147 | 155 | function traverseOwnerTreeUp( | 148 | 156 | hierarchy: Array<$FlowFixMe>, | 149 | | - instance: any, | | 157 | + instance: Fiber, | 150 | 158 | ): void { | 151 | 159 | if (__DEV__ || enableGetInspectorDataForInstanceInProduction) { | 152 | | - if (instance) { | 153 | | - hierarchy.unshift(instance); | 154 | | - traverseOwnerTreeUp(hierarchy, instance._debugOwner); | | 160 | + hierarchy.unshift(instance); | | 161 | + const owner = instance._debugOwner; | | 162 | + if (owner != null && typeof owner.tag === 'number') { | | 163 | + traverseOwnerTreeUp(hierarchy, (owner: any)); | | 164 | + } else { | | 165 | + // TODO: Traverse Server Components owners. | 155 | 166 | } | 156 | 167 | } | 157 | 168 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactCurrentFiber.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ import type {Fiber} from './ReactInternalTypes'; | 11 | 11 |
| 12 | 12 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | 13 | 13 | import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack'; | 14 | | -import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; | | 14 | +import {getComponentNameFromOwner} from 'react-reconciler/src/getComponentNameFromFiber'; | 15 | 15 |
| 16 | 16 | const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; | 17 | 17 |
| @@ -24,8 +24,8 @@ export function getCurrentFiberOwnerNameInDevOrNull(): string | null { | 24 | 24 | return null; | 25 | 25 | } | 26 | 26 | const owner = current._debugOwner; | 27 | | - if (owner !== null && typeof owner !== 'undefined') { | 28 | | - return getComponentNameFromFiber(owner); | | 27 | + if (owner != null) { | | 28 | + return getComponentNameFromOwner(owner); | 29 | 29 | } | 30 | 30 | } | 31 | 31 | return null; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.js +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,7 +68,7 @@ import { | 68 | 68 | TracingMarkerComponent, | 69 | 69 | } from './ReactWorkTags'; | 70 | 70 | import {OffscreenVisible} from './ReactFiberActivityComponent'; | 71 | | -import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; | | 71 | +import {getComponentNameFromOwner} from 'react-reconciler/src/getComponentNameFromFiber'; | 72 | 72 | import {isDevToolsPresent} from './ReactFiberDevToolsHook'; | 73 | 73 | import { | 74 | 74 | resolveClassForHotReloading, | @@ -110,6 +110,7 @@ import { | 110 | 110 | attachOffscreenInstance, | 111 | 111 | } from './ReactFiberCommitWork'; | 112 | 112 | import {getHostContext} from './ReactFiberHostContext'; | | 113 | +import type {ReactComponentInfo} from '../../shared/ReactTypes'; | 113 | 114 |
| 114 | 115 | export type {Fiber}; | 115 | 116 |
| @@ -475,7 +476,7 @@ export function createFiberFromTypeAndProps( | 475 | 476 | type: any, // React$ElementType | 476 | 477 | key: null | string, | 477 | 478 | pendingProps: any, | 478 | | - owner: null | Fiber, | | 479 | + owner: null | ReactComponentInfo | Fiber, | 479 | 480 | mode: TypeOfMode, | 480 | 481 | lanes: Lanes, | 481 | 482 | ): Fiber { | @@ -610,7 +611,7 @@ export function createFiberFromTypeAndProps( | 610 | 611 | "it's defined in, or you might have mixed up default and " + | 611 | 612 | 'named imports.'; | 612 | 613 | } | 613 | | - const ownerName = owner ? getComponentNameFromFiber(owner) : null; | | 614 | + const ownerName = owner ? getComponentNameFromOwner(owner) : null; | 614 | 615 | if (ownerName) { | 615 | 616 | info += '\n\nCheck the render method of `' + ownerName + '`.'; | 616 | 617 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberComponentStack.js +7-12Lines changed: 7 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,29 +29,24 @@ import { | 29 | 29 | } from 'shared/ReactComponentStackFrame'; | 30 | 30 |
| 31 | 31 | function describeFiber(fiber: Fiber): string { | 32 | | - const owner: null | Function = __DEV__ | 33 | | - ? fiber._debugOwner | 34 | | - ? fiber._debugOwner.type | 35 | | - : null | 36 | | - : null; | 37 | 32 | switch (fiber.tag) { | 38 | 33 | case HostHoistable: | 39 | 34 | case HostSingleton: | 40 | 35 | case HostComponent: | 41 | | - return describeBuiltInComponentFrame(fiber.type, owner); | | 36 | + return describeBuiltInComponentFrame(fiber.type); | 42 | 37 | case LazyComponent: | 43 | | - return describeBuiltInComponentFrame('Lazy', owner); | | 38 | + return describeBuiltInComponentFrame('Lazy'); | 44 | 39 | case SuspenseComponent: | 45 | | - return describeBuiltInComponentFrame('Suspense', owner); | | 40 | + return describeBuiltInComponentFrame('Suspense'); | 46 | 41 | case SuspenseListComponent: | 47 | | - return describeBuiltInComponentFrame('SuspenseList', owner); | | 42 | + return describeBuiltInComponentFrame('SuspenseList'); | 48 | 43 | case FunctionComponent: | 49 | 44 | case SimpleMemoComponent: | 50 | | - return describeFunctionComponentFrame(fiber.type, owner); | | 45 | + return describeFunctionComponentFrame(fiber.type); | 51 | 46 | case ForwardRef: | 52 | | - return describeFunctionComponentFrame(fiber.type.render, owner); | | 47 | + return describeFunctionComponentFrame(fiber.type.render); | 53 | 48 | case ClassComponent: | 54 | | - return describeClassComponentFrame(fiber.type, owner); | | 49 | + return describeClassComponentFrame(fiber.type); | 55 | 50 | default: | 56 | 51 | return ''; | 57 | 52 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactInternalTypes.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ import type { | 15 | 15 | Usable, | 16 | 16 | ReactFormState, | 17 | 17 | Awaited, | | 18 | + ReactComponentInfo, | 18 | 19 | ReactDebugInfo, | 19 | 20 | } from 'shared/ReactTypes'; | 20 | 21 | import type {WorkTag} from './ReactWorkTags'; | @@ -193,7 +194,7 @@ export type Fiber = { | 193 | 194 | // __DEV__ only | 194 | 195 |
| 195 | 196 | _debugInfo?: ReactDebugInfo | null, | 196 | | - _debugOwner?: Fiber | null, | | 197 | + _debugOwner?: ReactComponentInfo | Fiber | null, | 197 | 198 | _debugIsCurrentlyTiming?: boolean, | 198 | 199 | _debugNeedsRemount?: boolean, | 199 | 200 |
| |
|