Skip to content

The end of React-Hot-Loader #1024

Open
Open
@theKashey

Description

@theKashey

By this time we have reached limits of "hot replacement", and to overpass them we need something new. (Source issue : #1001)

The problem - there are so many ways to DEFINE react component, what we could not handle all of them.

The major problems today:

  • we are unable to replay all the changes. We knew only their result, not how they were made to repeat it. As result we could not inject code updates into the existing components. It is easy to update StatelessComponents or prototype-based Class-Component methods, or bound arrow function, but not everything one could possible use.
    For example:
 class App extends Component {
    memoizedFunction: reselect(function)  // <-- there is NO way we could "re-do" changes in `function`.
 }

Unfortunately - this could become a common thing with latest React changes. Already did( #995, #978, #969, #984)
I've spiked 2 different implementation - babel and Proxy based - they could work, but this is not the things I would like to have, not the way I would like to go.

  • we are changing types presented to React. Our greatest sideeffect. We have to wrap original type with a proxy to maintain type equality in the future. We should try our best to avoid it. Cold components are good try, not not enough.

Just a two points, we are unable to overtake.
React-Hot-Loader could handle most of the React code, and would fit for almost any project. But we are stuck.


I think React-Hot-Loader was a good spike, and it's time to more forward, and look to the way to to implement it inside React, stop hacking it, but start being a part of it:

  • don't try to maintain the single proxyfied component, applying all the changes to it, but just "explain" to React that some components could be the same, even if type got changes, and transfer variables changed during lifetime (state, for example) from the old one, to the new.
    Not trying to repeat the changes, but only to preserve state.

That will solve all the issues, and super simple to implement, as long we are already having everything we need for it, in the current RHL, but in much more complex form.

Something like componentComparator we spiked for Preact integration - https://github.com/gaearon/react-hot-loader/pull/960/files#diff-b26fdb1bb246da9739b0a423fbe9a65dR6, preactjs/preact#1120 - just expose RHL internals about compareAndSwap, and that's all.
Probably it just a hundred lines for everything - changed properties tracking from proxies, class comparator from hotRender, and nothing more.

It should not be super complex to integrate this to React, as long there are only two location to hook into.

As result - we could drop instantly hot-renderer, and next drop componentProxy - two major pieces of RHL.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions