Skip to content

v0.5.0-alpha

Pre-release
Pre-release
Compare
Choose a tag to compare
@gaearon gaearon released this 22 Aug 15:11
· 8 commits to deprecate since this release

React Hot API is superseded by React Proxy. This is meant to be the last release of React Hot API, with the new source code just delegating to React Proxy API.

It is recommended you do not use React Hot API anymore, and migrate projects to use React Proxy directly. There may be some breakage, so please make sure to report it. Unlike React Hot API, React Proxy is fully covered tests. React Hot Loader will also migrate to use React Proxy soon.

Breaking Changes

  • React 0.13 or later is now required.
  • The signature changes from (getRootInstances[, React]) => makeHot to ([getRootInstances,] React) => makeHot. Note: getRootInstances is only there to keep the old calls working, but we no longer need it, and you can safely stop passing it. Conversely, React is now a required argument. Since we expect React 0.13, we expect React.Component to be available.
  • We no longer check whether the passed class has a prototype and a render function. It is up to you now to guarantee that whatever's passed is a valid React component class. When React supports pure functions as components (in 0.14), we'll add support for them to React Proxy.
  • We no longer overwrite or even touch the original class. Every time makeHot is invoked, it will return a special proxy class. This means a caveat: for example, with React Hot Loader, static methods will only be hot-reloaded if you refer to them as this.constructor.doSomething() instead of FooBar.doSomething(). This is because React Hot Loader calls makeHot right before exporting, so FooBar still refers to the original class. Similarly, this.constructor === App will be false inside App unless you call App = makeHot(App) manually, which you can't do with React Hot Loader. I'm not sure how much of a problem this will be, so let me know if it pains you. In the longer term, we will deprecate React Hot Loader in favor of a Babel plugin which will be able to rewrite class definitions correctly, so it shouldn't be a problem for a long time. If there is demand, we can introduce a mode that rewrites passed classes, too.

API Changes

  • The goal of this release is to provide the new features of React Proxy to React Hot API consumers, so, apart from making React a required argument, and ignoring getRootInstances if it is passed, the API stays the same.
  • Nevertheless, if you depend on React Hot API, we suggest you to migrate to React Proxy.

Improvements and Bugfixes

  • There is no requirement to pass getRootInstances() anymore, so React Hot Loader doesn't need react/lib/ReactMount or walk the tree, which was somewhat fragile and changing between versions
  • Static methods and properties are now hot-reloaded
  • Instance getters and setters are now hot reloaded
  • Static getters and setters are now hot reloaded
  • Deleted instance methods are now deleted during hot reloading
  • Single method form of autobind-decorator is now supported

Things that Aren't There

These things didn't make the cut:

  • Error reporting (it is available in #23 but I don't want to support this project without tests so I'll move it)
  • Preserving DOM and state of classes decorated with HOCs. (This will be solved later with Babel plugin.)
  • Hot-reloading ES7 property syntax. (This will probably too be solved later with Babel plugin.)

Help Me Test This!

A React Hot Loader beta using this version will come out soon. Please help me test it! I'm sure there are many cases React Proxy doesn't handle yet, but at least we can write tests for them now.