Skip to content
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

[DevTools]: More compact rendering of deeply nested component trees when there is a single child #25040

Open
vjpr opened this issue Aug 4, 2022 · 1 comment

Comments

@vjpr
Copy link

vjpr commented Aug 4, 2022

On Reddit.com:

Screen Shot 2022-08-04 at 2 43 29 pm

It's a very common pattern in React to have deep chains of components with only one single child.

Options

a. VSCode style

This problem is also enountered in Java project trees.

VSCode does it like this:

image

https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_41.md#compact-folders-in-explorer

IntelliJ similar.

Maybe we could do the same as VSCode?

b. No indent for single child

Another approach would be to just not indent when there is only one child.

  h
  Context.Provider - {props: {foo: 1}}
  I
  Context.Provider
  E
  Context.Provider
  Context.Provider
  Context.Provider
  l
- Context.Provider (2 children - collapse all)

    mg
    d
    Context.Provider
  + Component (1 child - expand all)

    vg
    hg
    Context.Provider
  + hg (1 child - expand all)

We could also indicate when there are multiple children and provide some controls to collapse all the children's children. This would help with #16463.

Advantage: As another feature I'd also be interested in adding some inline annotations to the right of each component to show some props to better identify components. Moving these nested trees horizontal would block this ability, so this approach works better.

Design decision: Where to place the arrow to toggle folding? At the first element with multiple children (indicated above)? Or at the top. Or maybe we can create a really tall button on hover to show.

Design decision: How to clearly and visually deliniate that the components are nested vs siblings. Maybe we need to add an extra space (as shown in example above). Maybe color coding as well. Or alternate grey shading.

Related

@eps1lon eps1lon added Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Component: Developer Tools labels Aug 4, 2022
@lunaruan
Copy link
Contributor

Hey! Thanks for the suggestions! I think they definitely have potential and, I have some initial thoughts:
a. This seems like an interesting solution. It would make it easier to navigate the tree and might help with being able to figure out how many children a parent has. One difference between React DevTools and VSCode/IntelliJ though is that React could have arbitrarily long chains (vs file structures which are usually only so deep). Also, React components tend to have information, so we'd have to figure out the best way for developers to be able to access that (though that shouldn't be too hard).
b. This is also an interesting solution. We'd need a way to denote whether a component is a sibling or a single child of the parent component though.

Overall this is a really interesting idea though, and we'd love to think about this further!

@lunaruan lunaruan added Type: Feature Request and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants