Is there a Hot code push / Live-reload hook?

I built an app with React and I save the state of the app to a session variable on componentWillUnmount and load that variable back on componentWillMount. However, during a hot code push / live-reload, the component is never unmounted so its not saved. In fact, its hard to tell if its not just a refresh. Anyways, I’d like simply unmount the component to trigger the save. Are there any hooks for this? I coudlnt find any documentation.

1 Like

Yep! However I don’t think this is documented?

You can put this anywhere in your client code… I place it under client/_startup.js. You could also configure this to pop open something like Spotify that says you can press a button to reload.

Basically return true if you want it to reload or return false to suppress the hot reload. I usually just return false unless in the development env. This way they’ll get the new update the next full page load.

Reload._onMigrate(function (retry) {
  // set some global flag/session var here?

  if (app_is_in_devel) {
    return [true, {}];
  } else {
    return [false];

edit: here’s an example of the mobile package that will do a hot code reload once the app is put in the background then reloads on resume:

ah, here’s a nice vid to go along with the code :beers:


Thanks for that @cmather video! Thats what I needed.

We used the Migrate package too from @cmather (thanks a lot btw!), where we need to dispatch some events prior to hot code push. We found that the ready() event gets triggered at startup which messed things up for us. Here is what we did (inside a class):

self._startTime = new Date(); Session.set('readyToMigrate', false); self.onMigrate = onMigrate('router').ready(function() { if (new Date() - self._startTime < 1000) { console.log('onMigrate: Skipping startup'); } else if (Session.equals('readyToMigrate', false)) { console.log('onMigrate: Dispatching EXIT event'); // custom code - replace with yours self.dispatchEvent(new Event(this.EVENT_EXIT)); // delay to let the events above trickle setTimeout(function() { Session.set('readyToMigrate', true); }, 500); } return Session.equals('readyToMigrate', true); });

Thought it would help someone.

EDIT: can’t preformat JS properly, sorry.

1 Like