stencil icon indicating copy to clipboard operation
stencil copied to clipboard

feat: expose `Fragment` on `h`

Open simonhaenisch opened this issue 4 years ago • 5 comments

This way it's possible to set jsxFragmentFactory to h.Fragment in tsconfig, so that <></> syntax can be used without having to import Fragment explicitly (just importing h is sufficient).

simonhaenisch avatar Mar 09 '21 09:03 simonhaenisch

The broken test is from eec7651fa723658c2c8d853dc44b6316709b2317 (see https://github.com/ionic-team/stencil/runs/1796291494). All other tests pass locally.

simonhaenisch avatar Mar 09 '21 10:03 simonhaenisch

This is kind of cool!, i like it. My only concern is so performance regression because adding a property to an arrow function is disables some V8 optimization.

Wondering how we could check that

manucorporat avatar Mar 18 '21 14:03 manucorporat

Interesting, I didn't know that. Is this different when using a normal function h instead of assigning an anonymous arrow function to h? Do you have a link that explains this optimization? Is there a way to measure the impact of this?

BTW In the meantime what I did was to patch h at runtime with a globalScript.

import { h, Fragment } from '@stencil/core;

export default () => {
  if (!('Fragment' in h)) {
    h.Fragment = Fragment;
  }
}

(breaks spec tests with newSpecPage though)

simonhaenisch avatar Mar 18 '21 18:03 simonhaenisch

Hm, idea:

const h = () => { /* ... */ }

export default h

export const Fragment = (_, children) => children
import h from './h'

export { h }

simonhaenisch avatar Mar 18 '21 18:03 simonhaenisch

Never mind, mixing default and named exports doesn't seem to work with Rollup (see repl).

simonhaenisch avatar Mar 18 '21 19:03 simonhaenisch