Preact 4

https://github.com/preactjs/preact

  • Fix children being ignored when passed explicitly via props in certain cases. Fixes developit/preact-compat#44 (thanks @ld0rman!)

    Fun fact: this means you can now do: <div children={['hello!']} />

  • Bugfix: Fixes an issue caught by preact-compat's ref tests, where swapping the root node rendered by a component would null its ref twice.
  • Fix regression in 4.6.2 related to recycled component DOM not being treated as first render
  • A few small optimizations
  • Merge #106: removes some unnecessary code, drops ~50 bytes

  • Lazy-instantiate the internal mapping for linkState() and setState's callback queue.

    This reduces allocation cost for components. It also reduces overall memory consumption for classful components that don't make use of those given features (certainly the common case for setState callback)

  • Don't attempt to append a child to a parentNode if the child is the parentNode. Fixes Issue #126.
  • Optimize serialization of Objects to CSS strings to be about 5x faster (benchmark: https://esbench.com/bench/570daee0db965b9a009659f7)

  • Rethink solution to #120. TL;DR: fresh instances, cached DOM. Long version:

    Re-invoking the constructor on a class was not a great idea. Babel's transpiled constructors
    (and basically anything else) re-assign to the prototype, which is slow and a fairly bad idea.
    Also, and more importantly, it was assigning this.base to null, completely ignoring the
    main reason for caching components (caching their generated DOM using the component itself
    as a cache key). This commit changes the behavior to discard the cached component instance
    itself, re-using only the base by copying it to a fresh instance. Best of both worlds!

  • Fix for #122: don't assume Function.prototype exists, as it does not for Arrow Functions (thanks @LinusU!)
  • Fix regression since 4.5.0 where key tracking for components would fail in some cases, causing components not to be recycled. Relates to #98 and the second issue noted in #120.
  • Switch to a global/named symbol Symbol.for('preactattr') for the prop cache key (still falling back to __preactattr_).
  • Address the state re-use issue noted in Issue #120 by manually re-invoking component constructors when re-using components from the recycler.
  • Updated ESLint, announced preactjs.com website.

Bug Fixes

  • Fix context being null/undefined when unset. It should be an empty object.
  • Fix issue where ref (and key) were not being removed from props prior to being passed into component render (Issue #98)

Optimizations

  • Drop unnecessary cloning of props/context
  • Ship a more optimized default build by applying uglify-js without name mangling and with beautification (removes comments and applies dead code elimination)

Bug Fixes

  • When reclaiming externally created elements (such as via dangerouslySetInnerHTML), copy their attributes into the prop cache so they are properly diffed on subsequent render (Issue #97)
  • Fix cached unmount behavior: lifecycle events should be invoked for nested components, but only the top-level component should be physically removed from the DOM. The rest remain cached within that component's DOM + VDOM tree (Issue #94)
  • Fix exception thrown when removing/unsetting dangerouslySetInnerHTML
  • Fixed issue where setting the value prop for a <select> element could have no effect on initial render
  • Fix an issue where invoking refs may be skipped during unmount (ex: re-render swaps high-order components)
  • Fix a few cases where refs were invoked with the wrong value (Issue #87, thanks @chrisdavies)

Preact now explicitly removes falsey (false, null and undefined) properties and attributes from the DOM. This behaviour is consistent with React's. See #83 and #58.

  • Omit explicitly false JSX children to match the behavior of React (Issue #83).

This is purely a bug fix release, so be sure to update if you're using Preact 4.x.

Bugs Fixed:

  • Fix orphaned keyed VNodes not being removed in certain cases, such as when there are adjacent non-orphaned non-keyed VNodes (see developit/preact-compat#21)
  • When diffing a component against a non-component VNode, if the component render returns a different DOM node, make sure to reclaim the original node. (Issue #73)
  • Preact 4 is now officially out of beta. Please still report any bugs you find!
  • setState() callbacks should be called with the component as their context.
  • Fix multiple camelCase'd CSS properties (#66)
  • Fix child component refs not being invoked with null when the associated component is unmounted
  • Fix high order component refs linking to parent component when they should link to the child component/node.
  • Add support for refs!
  • Add support for defaultProps (static property on Components)
  • Possibly Breaking Change: cache rendered DOM with components when recycling
  • Possibly Breaking Change: don't wipe recycled DOM nodes, simply diff when re-used
  • Use setImmediate() to improve setState() performance where available
  • Skip empty values when serializing style objects
  • Coerce falsey className and style values to an empty string to avoid class="null" and style="null"
  • Rename missing component insert from <x-undefined-element> to <undefined>
  • Use a Symbol for storing the prop cache where available