Skip to content

fix(client): fix for possible crash on admin page

Dan Visel requested to merge admin-page-tweak into main

If I'm running my Kotahi locally, then kill it, then do a docker compose down, then a docker compose up, then reload a page left open (like http://localhost:4000/kotahi/ – one that is not http://localhost:4000), I get errors:

AdminPage.js:228 Uncaught TypeError: Cannot read properties of null (reading 'recentTab')
    at AdminPage (AdminPage.js:228:1)
    at ProxyFacade (react-hot-loader.development.js:830:1)
    at renderWithHooks (react-dom.development.js:14803:1)
...
12:23:04.347 react_devtools_backend_compact.js:2367 The above error occurred in the <AdminPage> component:
    in AdminPage
    in Route
    in Switch
    in Router (created by BrowserRouter)

If I go to localhost:4000 (where it's not trying to do a redirect), I get the regular app.

The reason for this: AdminPage is looking for currentUser.recentTab but currentUser is undefined at that moment, so this fails.

If I change that line to let dashboardRedirectUrl = currentUser?.recentTab (instead of currentUser.recentTab we don't get this crash.

I'm not sure how often this actually would happen in a non-local environment, but I think this change does make things safer.

Merge request reports