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
Proof of concept. Adding support for array returns from components. #703
Conversation
let childComponent = renderedChild && renderedChild.nodeName, toUnmount; | ||
|
||
if (typeof childComponent === 'function') { | ||
// set up high order component link |
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.
I did not explore this if branch at all.
} else { | ||
toUnmount = inst; | ||
|
||
component._component = inst = createComponent( |
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.
I think that _component may have to become an array for this to work. createComponent could accept an array and always return an array.
Yes, please 🙏🏽 |
From working on this on DIO 8, i've found a few things to take into account in reconciling fragments correctly, for example given the following children...
...assuming the array marked * is the fragment, there is specific behaviour/branches specifically for fragments in regards to.
Collectively these make supporting fragments a bit of a pain point without moving to a some variant of a linked list data-structure for children, but never the less worth it considering the opportunities it unlocks. |
fragments are tough. i had support for them in domvm v2 and dropped them in v3 [1]. you can see from the commit what it takes to get them working right. you must account for:
i had everything but the last bit working, which was ultimately the nail in the coffin. let's say you have this where every array is a fragment:
...and your dom looks like this: if you have have to swap the entire bc... fragment with the adjacent ghi... fragment, to get the dom to another related case is sibling reordering:
to
you at least double the number of i may re-add this functionality back, at some point, but i remember writing an exhaustive implementation was quite a pain. perhaps restricting array returns just to component roots may prove easier in Preact, or easier in general due to its different architecture. at minimum, i think this PR needs to implement and test sibling reordering, nested and adjacent fragment components; rendering a isolated fragment into the dom is a pretty contrived case that sidesteps the really hairy parts. [1] domvm/domvm@7a111ed#diff-5d2a48e9b3559cd73dac7b0a28bc2d97 |
Suport returning arrays from components is one of the greatest features added in react 16. |
I do not intend to work on this any further due to time constraints and hitting the walls @thysultan and @leeoniya mention. Someone else is more than welcome to take over from here. |
Good news! Array returns are supported in Preact X by wrapping any arrays with a |
This is filled with tons of quick hacks and is not meant to be merged. This is a proof of concept and is meant to start the conversation on what is possible and if this is even worth it.
As of opening this PR all karma tests are passing so no breaking changes.