-
Notifications
You must be signed in to change notification settings - Fork 49.8k
[DevTools] find best renderer when inspecting #24665
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
Changes from 8 commits
051a179
29841c9
276fc88
b7d225a
7a6b59f
975601b
48bba78
2e8c6c5
27b6756
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 |
|---|---|---|
|
|
@@ -309,22 +309,31 @@ export default class Agent extends EventEmitter<{| | |
| return renderer.getInstanceAndStyle(id); | ||
| } | ||
|
|
||
| getIDForNode(node: Object): number | null { | ||
| getBestMatchingRendererInterface(node: Object): RendererInterface | null { | ||
| let bestMatch = null; | ||
| for (const rendererID in this._rendererInterfaces) { | ||
| const renderer = ((this._rendererInterfaces[ | ||
| (rendererID: any) | ||
| ]: any): RendererInterface); | ||
|
|
||
| try { | ||
| const id = renderer.getFiberIDForNative(node, true); | ||
| if (id !== null) { | ||
| return id; | ||
| const fiber = renderer.getFiberForNative(node); | ||
| if (fiber !== null) { | ||
| // check if fiber.stateNode is matching the original hostInstance | ||
| if (fiber.stateNode === node) { | ||
| return renderer; | ||
| } else if (bestMatch === null) { | ||
| bestMatch = renderer; | ||
| } | ||
| } catch (error) { | ||
| // Some old React versions might throw if they can't find a match. | ||
| // If so we should ignore it... | ||
| } | ||
| } | ||
| // if an exact match is not found, return the first valid renderer as fallback | ||
| return bestMatch; | ||
| } | ||
|
|
||
| getIDForNode(node: Object): number | null { | ||
| const rendererInterface = this.getBestMatchingRendererInterface(node); | ||
| if (rendererInterface != null) { | ||
| return rendererInterface.getFiberIDForNative(node, true); | ||
|
||
| } | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now you're setting
bestMatchevery renderer wherefiberdoesn't equalnull. What do you think about keeping the original behavior if the exact fiber isn't found (ie. returning the first matching renderer)?