Bug: createElement doesn't support Fragment as root VNode.
See original GitHub issueDescribe the bug
The return type of Fragment
is VNode[]
.
https://github.com/aidenybai/million/blob/7ccc5f021df8ea384d5e03da165633238b52529f/src/jsx.ts#L110
However, createElement
doesn’t support passed in an array of VNode:
To Reproduce
import { createElement } from 'million';
function Example() {
return (
<>
{
['A', 'B', 'C'].map(i => (<div>{i}</div>))
}
</>
);
}
document.body.appendChild(createElement(Example));
Expected behavior
Render <div>A</div><div>B</div><div>C</div>
instead of <undefined></undefined>
.
Screenshots
No response
Operating System
Not applicable
Browser
Not applicable
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Support (or document non-support) for Fragments #946 - GitHub
We have a project written in Preact that is referencing a component from another library (written with React 16) that does not render...
Read more >Vue 3 Composition API - How to get the component element ...
In Vue 3, components are no longer limited at only 1 root element. ... you can specify the desired ref in createElement options:...
Read more >Guides | ServiceNow Developers
Creates a vnode for the virtual DOM from a string of HTML. ... virtual DOM libraries, nodes can be created by calling createElement(name,...
Read more >API Reference | Preact
Fragment. A special kind of component that can have children, but is not rendered as a DOM element. Fragments make it possible to...
Read more >Untitled
Inferno doesn't support legacy string refs, use `createRef` or callback `ref` API - Inferno provides lifecycle events on functional components.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After some thought and discussion with friends, I think it may be best to leave this out of Million.js’ featureset. I say this because this can fundamentally change some parts of the API – How would
createElement
deal with a fragment? Just return an array of elements in which the user needs to iterate over andappendChild
anyway?Additionally, the patch system would also need to be reworked, which is feel can make performance (marginally) worse and just less elegant in general. However, this isn’t to say Million will hard discourage the implementation of some sort of Fragment system for the live DOM. For instance, one could create their own
mount
system if need be.Plus, no other virtual dom library has support for this directly anyway, so Million.js would be unconventional in standard and poke out of the virtual dom definition if some sort of mounting system was implemented.
Let me know if you think my opinion can be corrected or have any questions.
@gustavopch Fragment will (likely) never be supported by the underlying Virtual DOM, but the react compat package will support Fragment