Feature suggestion: linked roots in devtools #477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An idea I had that would be handy for our use cases is a concept of "linked roots"
We have this structure in our application where we have multiple roots, each of them managed independently to achieve better scheduling of renders and hydrations, in coordination with code splitting.
This works for us well in practice, but the unfortunate side effect is that the dev tool tree view makes no sense any more – any child that is rendered in a different root is cut off from the main tree, and this makes it much harder to understand the component hierarchy.
The suggestion here is to implement this concept of "linked roots" that would let you link together two trees at the vnode level. This would not affect anything in preact core, but the devtools could understand to look for these links, and render component hierarchies with these. I'm thinking of them as a sort of sym-link for the devtools.
This is what it looks like in the devtools after, which is much closer to what we want:
I haven't gotten this far, but it'd be really neat if these were displayed differently in the dev tools. Possibly some annotation that the parent / child relationship is one of these "links"
Note: this doesn't work in v11 yet, so needs some thought about what's different there. I think it's because my method of setting
vnode.__linked_child
doesn't work in v11, but I haven't looked into that that much yet.Interested in your thoughts on this! It doesn't have to be this path exactly, but I'd be interested in knowing if you'd like to better support this pattern