Skip to content
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

Possible to render fragment 'null' instead of '[' ? #2640

Closed
vincehi opened this issue Nov 12, 2020 · 8 comments · Fixed by #2744 or webcomponents/custom-elements-everywhere#1616
Closed
Labels
Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions

Comments

@vincehi
Copy link

vincehi commented Nov 12, 2020

I would like to make the Mithril Fragment evolve to correspond to what typescript expects.

Mithril version: : 2.0.4

Browser and OS: safari 14.0 and Mac OS 10.15.7

Project: : no link

Expected Behavior

I would like to be able to create Fragment in this form

// Fragment
m(null, null, m("div", null, 'hello'), m ("div", null, 'word'))

Current Behavior

Currently it is necessary to do so:

m('[', null, m("div", null, 'hello'), m("div", null, 'word'))

Context

I want to compile .tsx files and since a little while ago typescript offers an option jsxFragmentFactory but this one expects a function like the other frameworks or null.
microsoft/TypeScript#38720 (comment)

@vincehi vincehi added the Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions label Nov 12, 2020
@orbitbot
Copy link
Member

@souricevincent

Didn't try it out, but would passing m.fragment in the compiler options for jsxFragmentFactory circumvent the whole situation?

@vincehi
Copy link
Author

vincehi commented Nov 12, 2020

@orbitbot

passing m.fragment in the typescript options jsxFragmentFactory doesn't work because it would give m(m.fragment, null, m('div', null, 'hello world')) and in mithril m.fragment is used as m.fragment(null, m('div', null, 'hello world')). And in Mithril, m.fragment(null, m('div', null, 'hello world')) is similar to m('[', null, m('div', null, 'hello world')). I can do a PR to change '[' by null to create a fragment

@dead-claudia
Copy link
Member

@orbitbot m.fragment does not work for JSX.

I would be open to an m.Fragment = '[' followed by lying about the type to TypeScript. (TypeScript makes far too many assumptions surrounding JSX, and there's an open issue I've commented in related to that.)

@vincehi
Copy link
Author

vincehi commented Nov 12, 2020

@isaaclyman m.Fragment = '[' It's a good idea, I'm doing PR soon.

@orbitbot
Copy link
Member

As a political standpoint, I'm a bit weary of making changes just to appease 3rd party tools.

@dead-claudia
Copy link
Member

@orbitbot I've been trying for over a year straight to get the TS team to make the necessary changes for us to be able to use our object component idiom, to no avail. Eventually you just kinda give up and start looking for solutions elsewhere. 😉

@josephspurrier
Copy link

Wow, setting "jsxFragmentFactory": "m.Fragment" in my tsconfig.json and then setting m.Fragment = '['; near the top of my index.js file gets fragments work for me in TypeScript. Now I can use <></> in my .tsx files. Thanks for the workaround!

@9r1nc3w1ll
Copy link

This might not be an elegant solution but creating a shim fixes it for me.
Pending when the issue is resolved.

Screenshot 2022-02-19 at 02 42 09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question For issues that are purely questions about Mithril, not necessarily bug reports or suggestions
Projects
Status: Closed
5 participants