@@ -2891,7 +2891,17 @@ export function attach(
2891
2891
2892
2892
function findAllCurrentHostFibers ( id : number ) : $ReadOnlyArray < Fiber > {
2893
2893
const fibers = [ ] ;
2894
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
2894
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
2895
+ if ( devtoolsInstance === undefined ) {
2896
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
2897
+ return fibers ;
2898
+ }
2899
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
2900
+ // TODO: Handle VirtualInstance.
2901
+ return fibers ;
2902
+ }
2903
+ const fiber =
2904
+ findCurrentFiberUsingSlowPathByFiberInstance(devtoolsInstance);
2895
2905
if (!fiber) {
2896
2906
return fibers ;
2897
2907
}
@@ -2925,7 +2935,17 @@ export function attach(
2925
2935
2926
2936
function findHostInstancesForElementID ( id : number ) {
2927
2937
try {
2928
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
2938
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
2939
+ if ( devtoolsInstance === undefined ) {
2940
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
2941
+ return null ;
2942
+ }
2943
+ if ( devtoolsInstance . kind !== FIBER_INSTANCE ) {
2944
+ // TODO: Handle VirtualInstance.
2945
+ return null ;
2946
+ }
2947
+ const fiber =
2948
+ findCurrentFiberUsingSlowPathByFiberInstance ( devtoolsInstance ) ;
2929
2949
if ( fiber === null ) {
2930
2950
return null ;
2931
2951
}
@@ -3028,18 +3048,10 @@ export function attach(
3028
3048
// https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactFiberTreeReflection.js
3029
3049
// It would be nice if we updated React to inject this function directly (vs just indirectly via findDOMNode).
3030
3050
// BEGIN copied code
3031
- function findCurrentFiberUsingSlowPathById ( id : number ) : Fiber | null {
3032
- const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
3033
- if ( devtoolsInstance === undefined ) {
3034
- console . warn ( `Could not find Fiber with id "${ id } "` ) ;
3035
- return null ;
3036
- }
3037
- if (devtoolsInstance.kind !== FIBER_INSTANCE) {
3038
- // TODO: Handle VirtualInstance.
3039
- return null ;
3040
- }
3041
-
3042
- const fiber = devtoolsInstance.data;
3051
+ function findCurrentFiberUsingSlowPathByFiberInstance (
3052
+ fiberInstance : FiberInstance ,
3053
+ ) : Fiber | null {
3054
+ const fiber = fiberInstance . data ;
3043
3055
const alternate = fiber . alternate ;
3044
3056
if ( ! alternate ) {
3045
3057
// If there is no alternate, then we only need to check if it is mounted.
@@ -3201,7 +3213,7 @@ export function attach(
3201
3213
function prepareViewElementSource ( id : number ) : void {
3202
3214
const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
3203
3215
if ( devtoolsInstance === undefined ) {
3204
- console . warn ( `Could not find Fiber with id "${ id } "` ) ;
3216
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
3205
3217
return ;
3206
3218
}
3207
3219
if (devtoolsInstance.kind !== FIBER_INSTANCE) {
@@ -3246,7 +3258,17 @@ export function attach(
3246
3258
}
3247
3259
3248
3260
function getOwnersList(id: number): Array< SerializedElement > | null {
3249
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
3261
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
3262
+ if ( devtoolsInstance === undefined ) {
3263
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
3264
+ return null ;
3265
+ }
3266
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
3267
+ // TODO: Handle VirtualInstance.
3268
+ return null ;
3269
+ }
3270
+ const fiber =
3271
+ findCurrentFiberUsingSlowPathByFiberInstance(devtoolsInstance);
3250
3272
if (fiber == null) {
3251
3273
return null ;
3252
3274
}
@@ -3275,7 +3297,18 @@ export function attach(
3275
3297
let instance = null ;
3276
3298
let style = null ;
3277
3299
3278
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
3300
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
3301
+ if ( devtoolsInstance === undefined ) {
3302
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
3303
+ return { instance, style} ;
3304
+ }
3305
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
3306
+ // TODO: Handle VirtualInstance.
3307
+ return { instance , style } ;
3308
+ }
3309
+
3310
+ const fiber =
3311
+ findCurrentFiberUsingSlowPathByFiberInstance ( devtoolsInstance ) ;
3279
3312
if ( fiber !== null ) {
3280
3313
instance = fiber . stateNode ;
3281
3314
@@ -3316,7 +3349,17 @@ export function attach(
3316
3349
}
3317
3350
3318
3351
function inspectElementRaw(id: number): InspectedElement | null {
3319
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
3352
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
3353
+ if ( devtoolsInstance === undefined ) {
3354
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
3355
+ return null ;
3356
+ }
3357
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
3358
+ // TODO: Handle VirtualInstance.
3359
+ return null ;
3360
+ }
3361
+ const fiber =
3362
+ findCurrentFiberUsingSlowPathByFiberInstance(devtoolsInstance);
3320
3363
if (fiber == null) {
3321
3364
return null ;
3322
3365
}
@@ -3505,10 +3548,6 @@ export function attach(
3505
3548
rootType = fiberRoot . _debugRootType ;
3506
3549
}
3507
3550
3508
- const devtoolsInstance: DevToolsInstance = (idToDevToolsInstanceMap.get(
3509
- id,
3510
- ): any);
3511
-
3512
3551
let isErrored = false;
3513
3552
let targetErrorBoundaryID;
3514
3553
if (isErrorBoundary(fiber)) {
@@ -3699,7 +3738,7 @@ export function attach(
3699
3738
3700
3739
const devtoolsInstance = idToDevToolsInstanceMap.get(id);
3701
3740
if (devtoolsInstance === undefined) {
3702
- console . warn ( `Could not find Fiber with id "${ id } "` ) ;
3741
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
3703
3742
return ;
3704
3743
}
3705
3744
if (devtoolsInstance.kind !== FIBER_INSTANCE) {
@@ -3841,9 +3880,7 @@ export function attach(
3841
3880
// Log error & cause for user to debug
3842
3881
console . error ( message + '\n\n' , error ) ;
3843
3882
if ( error . cause != null ) {
3844
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
3845
- const componentName =
3846
- fiber != null ? getDisplayNameForFiber ( fiber ) : null ;
3883
+ const componentName = getDisplayNameForElementID ( id ) ;
3847
3884
console . error (
3848
3885
'React DevTools encountered an error while trying to inspect hooks. ' +
3849
3886
'This is most likely caused by an error in current inspected component' +
@@ -3945,7 +3982,7 @@ export function attach(
3945
3982
? mostRecentlyInspectedElement
3946
3983
: inspectElementRaw ( id ) ;
3947
3984
if ( result === null ) {
3948
- console . warn ( `Could not find Fiber with id "${ id } "` ) ;
3985
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
3949
3986
return ;
3950
3987
}
3951
3988
@@ -3986,7 +4023,17 @@ export function attach(
3986
4023
hookID : ?number ,
3987
4024
path : Array < string | number > ,
3988
4025
): void {
3989
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
4026
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
4027
+ if ( devtoolsInstance === undefined ) {
4028
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
4029
+ return ;
4030
+ }
4031
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
4032
+ // TODO: Handle VirtualInstance.
4033
+ return ;
4034
+ }
4035
+ const fiber =
4036
+ findCurrentFiberUsingSlowPathByFiberInstance(devtoolsInstance);
3990
4037
if (fiber !== null) {
3991
4038
const instance = fiber . stateNode ;
3992
4039
@@ -4042,7 +4089,17 @@ export function attach(
4042
4089
oldPath : Array < string | number > ,
4043
4090
newPath: Array< string | number > ,
4044
4091
): void {
4045
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
4092
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
4093
+ if ( devtoolsInstance === undefined ) {
4094
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
4095
+ return ;
4096
+ }
4097
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
4098
+ // TODO: Handle VirtualInstance.
4099
+ return ;
4100
+ }
4101
+ const fiber =
4102
+ findCurrentFiberUsingSlowPathByFiberInstance(devtoolsInstance);
4046
4103
if (fiber !== null) {
4047
4104
const instance = fiber . stateNode ;
4048
4105
@@ -4108,7 +4165,17 @@ export function attach(
4108
4165
path : Array < string | number > ,
4109
4166
value: any,
4110
4167
): void {
4111
- const fiber = findCurrentFiberUsingSlowPathById ( id ) ;
4168
+ const devtoolsInstance = idToDevToolsInstanceMap . get ( id ) ;
4169
+ if ( devtoolsInstance === undefined ) {
4170
+ console . warn ( `Could not find DevToolsInstance with id "${ id } "` ) ;
4171
+ return ;
4172
+ }
4173
+ if (devtoolsInstance.kind !== FIBER_INSTANCE) {
4174
+ // TODO: Handle VirtualInstance.
4175
+ return ;
4176
+ }
4177
+ const fiber =
4178
+ findCurrentFiberUsingSlowPathByFiberInstance(devtoolsInstance);
4112
4179
if (fiber !== null) {
4113
4180
const instance = fiber . stateNode ;
4114
4181
0 commit comments