@@ -28,6 +28,7 @@ import {
2828 processChildContext ,
2929} from './ReactFiberContext' ;
3030import { createFiberRoot } from './ReactFiberRoot' ;
31+ import * as ReactFiberDevToolsHook from './ReactFiberDevToolsHook' ;
3132import ReactFiberScheduler from './ReactFiberScheduler' ;
3233import { insertUpdateIntoFiber } from './ReactFiberUpdateQueue' ;
3334import ReactFiberInstrumentation from './ReactFiberInstrumentation' ;
@@ -211,6 +212,23 @@ type HydrationHostConfig<T, P, I, TI, C, CX, PL> = {
211212 ) : void ,
212213} ;
213214
215+ // 0 is PROD, 1 is DEV.
216+ // Might add PROFILE later.
217+ type BundleType = 0 | 1 ;
218+
219+ type DevToolsConfig < I , TI > = { |
220+ bundleType : BundleType ,
221+ version : string ,
222+ rendererPackageName : string ,
223+ // Note: this actually *does* depend on Fiber internal fields.
224+ // Used by "inspect clicked DOM element" in React DevTools.
225+ findFiberByHostInstance ?: ( instance : I | TI ) => Fiber ,
226+ // Used by RN in-app inspector.
227+ // This API is unfortunately RN-specific.
228+ // TODO: Change it to accept Fiber instead and type it properly.
229+ getInspectorDataForViewTag ?: ( tag : number ) => Object ,
230+ | } ;
231+
214232export type Reconciler < C , I , TI > = {
215233 createContainer ( containerInfo : C , hydrate : boolean ) : OpaqueRoot ,
216234 updateContainer (
@@ -223,6 +241,7 @@ export type Reconciler<C, I, TI> = {
223241 unbatchedUpdates < A > ( fn : ( ) => A ) : A ,
224242 flushSync < A > ( fn : ( ) => A ) : A ,
225243 deferredUpdates < A > ( fn : ( ) => A ) : A ,
244+ injectIntoDevTools ( config : DevToolsConfig < I , TI > ) : boolean ,
226245
227246 // Used to extract the return value from the initial render. Legacy API.
228247 getPublicRootInstance (
@@ -327,6 +346,14 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
327346 scheduleWork ( current , expirationTime ) ;
328347 }
329348
349+ function findHostInstance ( fiber : Fiber ) : PI | null {
350+ const hostFiber = findCurrentHostFiber ( fiber ) ;
351+ if ( hostFiber === null ) {
352+ return null ;
353+ }
354+ return hostFiber . stateNode ;
355+ }
356+
330357 return {
331358 createContainer ( containerInfo : C , hydrate : boolean ) : OpaqueRoot {
332359 return createFiberRoot ( containerInfo , hydrate ) ;
@@ -386,13 +413,7 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
386413 }
387414 } ,
388415
389- findHostInstance ( fiber : Fiber ) : PI | null {
390- const hostFiber = findCurrentHostFiber ( fiber ) ;
391- if ( hostFiber === null ) {
392- return null ;
393- }
394- return hostFiber . stateNode ;
395- } ,
416+ findHostInstance ,
396417
397418 findHostInstanceWithNoPortals ( fiber : Fiber ) : PI | null {
398419 const hostFiber = findCurrentHostFiberWithNoPortals ( fiber ) ;
@@ -401,5 +422,22 @@ export default function<T, P, I, TI, PI, C, CC, CX, PL>(
401422 }
402423 return hostFiber . stateNode ;
403424 } ,
425+
426+ injectIntoDevTools ( config : DevToolsConfig < I , TI > ) : boolean {
427+ const { findFiberByHostInstance} = config ;
428+ return ReactFiberDevToolsHook . injectInternals ( {
429+ ...config ,
430+ findHostInstanceByFiber ( fiber : Fiber ) : I | TI | null {
431+ return findHostInstance ( fiber ) ;
432+ } ,
433+ findFiberByHostInstance ( instance : I | TI ) : Fiber | null {
434+ if ( ! findFiberByHostInstance ) {
435+ // Might not be implemented by the renderer.
436+ return null ;
437+ }
438+ return findFiberByHostInstance ( instance ) ;
439+ } ,
440+ } ) ;
441+ } ,
404442 } ;
405443}
0 commit comments