preact v10.0.0-alpha.2 Release Notes
Release Date: 2019-03-14 // about 5 years ago-
๐ The weekend is coming and we thought it be a good time to make another alpha release for everyone to play with ๐
๐ฑ This was a wonderful week for us. More and more bug reports contain links to a reproducible test case. You all are simply amazing! We wouldn't be able to fix this many bugs without all your help ๐ Even our contributions had an alltime high with excellent PRs from the community!
๐ฆ Despite fixing many bugs we landed a new package to help you test hooks in Preact ๐
โ Introducing
preact/test-utils
โฑ With hooks having their own scheduling logic, we didn't have a good testing story up until now! First-time contributor @JoviDeCroock went right into it and quickly had a prototype running. With the blink of an eye he had a PR that was ready to be merged. These testing utilities are inspired by the excellent
react-dom/test-utils
tools and share a similaract()
function ๐๐ For testing hooks effectively we need to flush pending effects synchronously. The brand new
act()
function allows you to do just that:import { act } from "preact/test-utils";let spy = sinon.spy();function StateContainer() { useEffect(spy); return \<div /\>; }// Wrap the render() with `act` to flush hooks automaticallyact(() =\> render(\<StateContainer /\>, document.body));// Do your assertions ๐expect(spy).to.be.calledOnce;
โก๏ธ If you're working with
class
-based components you can use the newsetupRerender
function to flush pending state updates in your tests:import { setupRerender, Component } from "preact/test-utils";// Setup rerender logic firstconst rerender = setupRerender();let updateState;class App extends Component { constructor() { super(); this.state = { count: 0 }; updateState = () =\> this.setState(prev =\> ({ count: ++prev.count })); } render() { return \<div\>count: {this.state.count]}\</div\>; } }// Render your componentrender(\<App /\>, dom);expect(dom.textContent).to.equal("count: 0");// Trigger a state updateupdateState();// Flush all state updatesrerender();expect(dom.textContent).to.equal("count: 1");
๐ฑ It's his first contribution to Preact and we couldn't be more ecstatic about his work. Give him a round of applause ๐ It's also good to know for us that our code remains very accessible for new contributors.
๐ Bug-Fixes
- ๐ Fix devtools not loading (#1360, thanks @calebeby)
- Inline vnode children (#1317, thanks @developit)
- โ Remove double Promise on initialization (#1370, thanks @bmeurer and @marvinhagemeister)
- ๐ Fix camelCase
style
properties not working (#1375, thanks @mochiya98) - ๐ Fix
Portal
rendering undefined tags into the DOM (#1367, thanks @marvinhagemeister) - ๐ Fix
this.props
not set forPureComponent
components (#1384, thanks @marvinhagemeister) - ๐ Use
console.error
for caught errors in the devtools adapter (#1385, thanks @yuqianma) - ๐ Fix state not updated when
setState
is called incomponentWillReceiveProps
(#1369, thanks @mochiya98) - ๐ Fix svg
foreignObject
not being treated as svg (#1391, thanks @marvinhagemeister) - ๐ Fix
onBeforeInput
not attaching event handler (#1366, thanks @marvinhagemeister) - ๐ Fix
React.isValidElement
check failing forvnodes
created with Preact (#1380, thanks @marvinhagemeister) - ๐ Fix
<select>.value
not working (#1397, thanks @JoviDeCroock) - ๐ Fix multiple selections for
<select>
only selecting last item (#1405, thanks @JoviDeCroock) - ๐ Fix
force
flag blocking state update in secondrender()
(#1377, thanks @developit) - ๐ Fix IE11 crashing because of missing
Element.prototype.remove
(#1395, thanks @marvinhagemeister) - ๐ Fix
forwardRef
andmemo
ignoring refs when composed together (#1358, thanks @marvinhagemeister)
๐ Performance
- ๐ Move
_prevState
for devtools out of core (#1379, thanks @developit) - Reuse
oldChildrenLength
to save bytes (#1386, thanks @yuqianma) - ๐
Don't call
setProperty
for style strings (#1394, thanks @choumx)
Other
- ๐ Fix unable to satisfy type parameters for
static
methods (#1365, thanks @marvinhagemeister) - โ Add back missing camelCase attributes (#1390, thanks @marvinhagemeister)
- โ Add missing autocorrect attribute types (#1393, thanks @garybernhardt)
- Ignore final new line for all
mangle.json
files (#1378, thanks @developit) - โ Add more tests for
componentWillReceiveProps
(#1387, thanks @developit)