Skip to content

Commit

Permalink
Make injecting findFiberByHostInstance optional so future versions ca…
Browse files Browse the repository at this point in the history
…n drop it
  • Loading branch information
sebmarkbage committed Aug 28, 2024
1 parent 6072e52 commit db89895
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 1 addition & 11 deletions packages/react-devtools-shared/src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,7 @@ export function registerRenderer(
renderer: ReactRenderer,
onErrorOrWarning?: OnErrorOrWarning,
): void {
const {
currentDispatcherRef,
getCurrentFiber,
findFiberByHostInstance,
version,
} = renderer;

// Ignore React v15 and older because they don't expose a component stack anyway.
if (typeof findFiberByHostInstance !== 'function') {
return;
}
const {currentDispatcherRef, getCurrentFiber, version} = renderer;

// currentDispatcherRef gets injected for v16.8+ to support hooks inspection.
// getCurrentFiber gets injected for v16.9+.
Expand Down
7 changes: 6 additions & 1 deletion packages/react-devtools-shared/src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export function initBackend(

// Inject any not-yet-injected renderers (if we didn't reload-and-profile)
if (rendererInterface == null) {
if (typeof renderer.findFiberByHostInstance === 'function') {
if (
// v16-19
typeof renderer.findFiberByHostInstance === 'function' ||
// v16.8+
renderer.currentDispatcherRef != null
) {
// react-reconciler v16+
rendererInterface = attach(hook, id, renderer, global);
} else if (renderer.ComponentTree) {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ export type Lane = number;
export type Lanes = number;

export type ReactRenderer = {
findFiberByHostInstance: (hostInstance: HostInstance) => Fiber | null,
version: string,
rendererPackageName: string,
bundleType: BundleType,
// 16.0+ - To be removed in future versions.
findFiberByHostInstance?: (hostInstance: HostInstance) => Fiber | null,
// 16.9+
overrideHookState?: ?(
fiber: Object,
Expand Down

0 comments on commit db89895

Please sign in to comment.