Skip to content

v10.0.0

Latest

Choose a tag to compare

@Havunen Havunen released this 04 Oct 11:35
993eaeb

10.0.0

This release compiles JSX for Inferno 10. The plugin now calls Inferno 10's newVNode factories, which take the shape of the children inside the vNode flags. It also removes $ReCreate, and it stops the build when a child flag cannot match the children it is written on.

From this release on, the major version of the plugin matches the major version of Inferno: use plugin 10.x with Inferno 10.x, plugin 11.x with Inferno 11.x, and so on. There is no plugin 8 or 9. For Inferno 9 and older, keep using plugin 7.

Breaking changes

Inferno 10 is required

The compiled code calls the Inferno 10 factories:

Plugin 7 Plugin 10
createVNode newVNode
createComponentVNode newComponentVNode
createFragment newFragment
createTextVNode newTextVNode

normalizeProps is unchanged.

The child flags are no longer a separate argument. Each vNode gets one number that holds both its type and the shape of its children, using the VNodeFlags of inferno-vnode-flags 10. Inferno 10 also renumbered these flags, so code compiled by plugin 7 does not work with Inferno 10 and has to be compiled again. This includes packages that ship JSX compiled by plugin 7.

<div>Hello</div>
// 7.x
createVNode(1, "div", null, "Hello", 16);
// 10.x: HtmlElement (1) + HasTextChildren (2)
newVNode(3, "div", null, "Hello");

<><a /><b /></>
// 7.x
createFragment([createVNode(1, "a"), createVNode(1, "b")], 4);
// 10.x: Fragment (256) + HasNonKeyedChildren (4)
newFragment(260, [newVNode(17, "a"), newVNode(17, "b")]);

Children that are only known at runtime, such as {expression}, get no child bit, and Inferno normalizes them. Components get ComponentUnknown, which is now 0. The README lists all the flag values.

$Flags takes Inferno 10 flag values

$Flags={expression} still replaces the flags of the vNode. The value is now read as Inferno 10 VNodeFlags, and the plugin adds the child bit of the children to it. Components also get HasInvalidChildren (16). Update any numbers you pass. For example, $Flags={64} meant InputElement in plugin 7 and means SvgElement in plugin 10.

Flag Inferno 9 Inferno 10
HtmlElement 1 1
ComponentUnknown 2 0
ComponentClass 4 128
ComponentFunction 8 8192
SvgElement 32 64
InputElement 64 512
TextareaElement 128 2048
SelectElement 256 4096
ContentEditable 4096 131072

$ChildFlag keeps the ChildFlags values: 0, 1, 2, 4, 8 and 16.

$ReCreate is removed

Inferno 10 has no ReCreate flag. The plugin throws for $ReCreate on any element, component or Fragment, whatever the uselessFlags option is. To re-create an element, change its key instead. Inferno unmounts the old element and mounts a new one when the key changes.

// 7.x
<section $ReCreate>{content}</section>
// 10.x
<section key={version}>{content}</section>

Child flags that cannot match the children are compile errors

When the JSX shows that the children cannot have the shape a child flag declares, the plugin now throws an error that points at the flag. Before, the plugin ignored the flag or passed it on to Inferno, which then rendered the children wrong or threw in development.

// An array is not a single vNode
<div $HasVNodeChildren><a/><b/></div>
<div $HasVNodeChildren>{[a, b]}</div>

// Text is not a vNode, and an element is not text
<div $HasVNodeChildren>text</div>
<div $HasTextChildren><a/></div>

// One element is not an array, and keyed children need keys
<ul $HasNonKeyedChildren><li/></ul>
<ul $HasKeyedChildren><li key="1"/><li/></ul>

// Not a ChildFlags value
<div $ChildFlag={3}>{a}</div>
SyntaxError: /project/src/App.jsx: $HasVNodeChildren needs one element or component child, but there are 2 children.
> 1 | <div $HasVNodeChildren><a/><b/></div>
    |      ^^^^^^^^^^^^^^^^^

Dynamic children such as {expression} are not checked, and neither are the children of components. The uselessFlags option does not turn this check off.

A ref without a value is a compile error

<div ref /> compiled to a true ref, which is neither a callback nor a ref object. Give the ref an explicit value.

The pragma options rename the Inferno 10 factories

pragma, pragmaCreateComponentVNode, pragmaFragmentVNode and pragmaTextVNode now replace newVNode, newComponentVNode, newFragment and newTextVNode. A custom function set with these options gets the new arguments: newVNode(flags, type, className, children, props, key, ref) has no childFlags argument, and newFragment(flags, children, key) takes the flags first.

Changes

$ChildFlag

  • A numeric $ChildFlag is folded into the flags like the other child flags. <div $ChildFlag={2}>{a}</div> compiles to newVNode(9, "div", null, a).
  • A $ChildFlag expression is only known at runtime, so that element or Fragment is compiled to Inferno's deprecated createVNode or createFragment, which convert the value. The plugin imports them next to the new factories when they are needed. These two calls do not use the pragma options.
<div $ChildFlag={flag}>{a}</div>
// compiles to
createVNode(1, "div", null, a, flag);

Smaller output

  • null values of className, key, ref and children are left out. <div className={null} key={null} ref={null} /> compiled to createVNode(1, "div", null, null, 1, null, null, null) and now compiles to newVNode(17, "div"). Other props keep their null values.
  • A {null} child is left out too. <Fragment>{null}</Fragment> compiles like an empty Fragment: newFragment(272).

Bug fixes

  • A single dynamic child of a Fragment with a $ChildFlag was put in an array. <Fragment $ChildFlag={x}>{a}</Fragment> compiled to createFragment([a], x), so the flag described the array instead of the value. The child is now passed as written: createFragment(a, x). Static children are still put in an array.

Development

  • New tests cover the packed flags, the child flag errors, $ReCreate and valueless refs.
  • The benchmark fixture no longer uses $ReCreate.
  • Dev dependencies updated, including chai 6.3, ESLint 10.12, Mocha 12.0.3 and Rollup 4.64. inferno 10 is added as a dev dependency.

Upgrading

  1. Upgrade inferno and babel-plugin-inferno to 10 together, and follow the Inferno 10 migration guide.
  2. Compile everything again, including dependencies that ship JSX compiled by plugin 7.
  3. Replace $ReCreate with a changing key.
  4. Fix the child flags that the new errors point at. Usually the flag can be removed, because the plugin sets the child flags of JSX children itself.
  5. Give every ref a value.
  6. Update the numbers in $Flags to the Inferno 10 values, and update custom pragma functions to the new arguments.