react-af icon indicating copy to clipboard operation
react-af copied to clipboard

Better Fragment emulation

Open benwiley4000 opened this issue 6 years ago • 5 comments

<div> is an imperfect Fragment replacement since it can screw with layout under certain circumstances. I wrote a polyfill for Fragment - it works by rendering a div with children, attaching the children to the div's parent, and hiding the div from the page - what do you think?

benwiley4000 avatar Mar 14 '18 22:03 benwiley4000

@benwiley4000, My concern with this approach is that there is a lot of adding and removing of divs to/from the real DOM whenever a component re-renders. I understand that a simple div isn't the same as a Fragment, but it codes the same and is more performant than your approach.

donavon avatar Mar 19 '18 14:03 donavon

@donavon I understand your point! However I suspect this will be more of a problem than you think. The first case in my own code where I tried polyfilling fragment with div I experienced unforgivable layout issues.

In my own testing I believe this polyfill is performant (I couldn't see any issues, but perhaps there would be on slow machines or very large child sets). In any case I think a possible small performance drop is an acceptable trade-off for better behavior matching, though you might not agree.

benwiley4000 avatar Mar 19 '18 14:03 benwiley4000

@benwiley4000, I'm open to a PR if you'd like to take a stab at it. ;)

donavon avatar Mar 20 '18 20:03 donavon

You could use react-addons-create-fragment in older Reacts instead: https://reactjs.org/docs/create-fragment.html

suchipi avatar Mar 20 '18 21:03 suchipi

Maybe I misunderstood what that did, but I thought it still required a div wrapper.

On Tue, Mar 20, 2018 at 5:57 PM, suchipi [email protected] wrote:

You could use react-addons-create-fragment in older Reacts instead: https://reactjs.org/docs/create-fragment.html

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/donavon/react-af/issues/1#issuecomment-374771204, or mute the thread https://github.com/notifications/unsubscribe-auth/AM7h7Wuqq4XpFGart39aJCgu4A67QFX4ks5tgXtMgaJpZM4SrReS .

benwiley4000 avatar Mar 20 '18 21:03 benwiley4000