Skip to content

Instantly share code, notes, and snippets.

@pl12133
Last active June 13, 2019 05:42
Show Gist options
  • Save pl12133/4a3978bd11eb3e4c7a81aa52fdbd0eb4 to your computer and use it in GitHub Desktop.
Save pl12133/4a3978bd11eb3e4c7a81aa52fdbd0eb4 to your computer and use it in GitHub Desktop.
Preact@8 to Preact@10 Upgrade Notes

PreactX Upgrade Experience

Obvious breaking changes

See release 10.0.0-alpha.0 for a full list.

  • h -> createElement
  • VNode.nodeName -> VNode.type
  • VNode.attributes -> VNode.props
  • VNode.children -> VNode.props.children
  • require('preact/devtools') -> require('preact/debug')
  • preact-compat -> preact/compat
  • render signature changed
    • see explanation in release notes
  • JSX Attribute style no longer supported as string, must be object.
  • children no longer guarenteed to be Array:
    • you can get the old behavior by using the new toChildArray export from Preact
  • preact-portal#Portal -> preact/compat#createPortal

preactjs/migrate-preact-x was very helpful.

Modules that need updating:

Non-obvious breaking changes

Event listeners can no longer be falsey

The following pattern will need to be changed:

// Preact 8:
<button onClick={active && this.handleClick}>My Button</button>

// Preact X:
<button {...active && { onClick: this.handleClick }}>My Button</button>

VNode.constructor is undefined

// Preact 8
assert(typeof preact.h('span').constructor === 'function')

// Preact X
assert(typeof preact.createElement('span').constructor === 'undefined')
@developit
Copy link

Tip:

import { options } from 'preact';

function VNode() {}  // what used to come back from preact.h('a').constructor

VNode.prototype.foo = 'bar'; // imagine it was being extended

let old = options.vnode;
options.vnode = vnode => {
  Object.assign(vnode, VNode.prototype);
  if (old) old(vnode);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment