question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: createElement doesn't support Fragment as root VNode.

See original GitHub issue

Describe 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:

https://github.com/aidenybai/million/blob/1ea5443220a9d7caf1512862a3b24e968548e638/src/createElement.ts#L10-L13

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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
aidenybaicommented, Nov 26, 2021

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 and appendChild 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.

1reaction
aidenybaicommented, Jun 15, 2022

@gustavopch Fragment will (likely) never be supported by the underlying Virtual DOM, but the react compat package will support Fragment

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found