1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/errors/no-on-app-updated-hook.md
Arunoda Susiripala a32b22bb2d
Remove special error script handling (#3849)
* Remove special error script handling.
As a result of that, we can't detect 500 errors and buildIdMismatch via client side.

* Fix failing test cases.

* Refactor the code base.

* Remove Router.onAppUpdated
2018-02-21 23:11:25 +05:30

1.1 KiB

Router.onAppUpdated is removed

Due to this bug fix, we had to remove the Router.onAppUpdated hook. But the default functionality of this feature is still in effect.

We use this hook to detect a new app deployment when switching pages and act accordingly. Although there are many things you can do in this hook, it's often used to navigate the page via the server as shown below:

Router.onAppUpdated = function(nextRoute) {
  location.href = nextRoute
}

In this hook, you can't wait for a network request or a promise to get resolved. And you can't block the page navigation. So, the things you can do is limited.

One real use of this hook is to persist your application state to local-storage before the page navigation. For that, you can use the window.onbeforeunload hook instead.

This is code for that:

window.onbeforeunload = function(e) {
  // Get the application state (usually from a store like Redux)
  const appState = {}
  localStorage.setItem('app-state', JSON.stringify(appState));
};