React-devtools: $r doesn't highlight Stateless Functional Components

Created on 2 Sep 2018  路  2Comments  路  Source: facebook/react-devtools

Typing $r in the console prints the nearest ancestor component that is not a stateless functional one.

Test case: https://github.com/mgol/react-tic-tac-toe

When highlighted in the React DevTools, only the top-level stateful Game component is displayed when $r is typed, no matter which one is selected.

Most helpful comment

Thanks for the explanation.

One issue is that React DevTools display == $r next to the selected JSX node, whether it's a component instance or a DOM element. Having $r returns something completely different to what the UI claims is confusing. Especially that now I see it doesn't return the ancestor component but just whatever "working" thing $r pointed to previously. I guess this is the same what #929 reports. Wouldn't returning an object like:

{
    displayName: 'Board',
    props: {/* Board props */}
}

be a good idea, even if it has no direct internal presence? If you want to keep existing behavior I would keep the == $r mark next to the last selected element so that it's accurate.

All 2 comments

$r is a convenience pointer that will refer to either the currently selected DOM element _or_ the currently selected component _instance_. Since functional components have no instance, there's nothing for it to point to.

So basically, to me, it sounds like this is working as designed.

Thanks for the explanation.

One issue is that React DevTools display == $r next to the selected JSX node, whether it's a component instance or a DOM element. Having $r returns something completely different to what the UI claims is confusing. Especially that now I see it doesn't return the ancestor component but just whatever "working" thing $r pointed to previously. I guess this is the same what #929 reports. Wouldn't returning an object like:

{
    displayName: 'Board',
    props: {/* Board props */}
}

be a good idea, even if it has no direct internal presence? If you want to keep existing behavior I would keep the == $r mark next to the last selected element so that it's accurate.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aganglada picture aganglada  路  4Comments

inoyakaigor picture inoyakaigor  路  4Comments

sophiebits picture sophiebits  路  5Comments

xuzhanhh picture xuzhanhh  路  3Comments

BrandonWade picture BrandonWade  路  4Comments