planetarium / 9c-launcher

Nine Chronicles Launcher
GNU General Public License v3.0
44 stars 37 forks source link

string "undefined" stored in 'lastAddress' of Local Storage, causing uncaught exception error. #2343

Closed Akamig closed 12 months ago

Akamig commented 1 year ago

image

https://github.com/planetarium/9c-launcher/blob/08e9098f9e6da48483917937afd7fd869cc8a36d/src/renderer/views/LoginView/index.tsx#L38C6-L50

From what I assume, in the process of getLastLoggedinAddress() when LoginView first rendered, if there's no "lastAddress" in local storage, it access to first entry of accountStore.addresses[0], and if accountStore is not initialized properly in render time for some reason, it will return undefined, and be implicitly type converted when attempt to login in such state, causing this error on next launcher execution.

Possible solution is,

  1. filter non-hexadecimal string from line 40
  2. Fix rendering order and prevent this from happening.
Akamig commented 12 months ago

Related Log :

[1] 15:47:30.747 › Warning: React has detected a change in the order of Hooks called by App. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks
[1] 
[1]    Previous render            Next render
[1]    ------------------------------------------------------
[1] 1. useState                   useState
[1] 2. useState                   useState
[1] 3. useRef                     useRef
[1] 4. useDebugValue              useDebugValue
[1] 5. useEffect                  useEffect
[1] 6. useContext                 useContext
[1] 7. useEffect                  useEffect
[1] 8. undefined                  useContext
[1]    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] 
[1]     at observerComponent (webpack-internal:///../node_modules/mobx-react-lite/es/observer.js:49:73)
[1] 15:47:30.750 › Download the Apollo DevTools for a better development experience: https://chrome.google.com/webstore/detail/apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm
[1] 15:47:30.772 › Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
[1] 
[1] Check the render method of `LoginView`.
[1]     at Controller (webpack-internal:///../node_modules/react-hook-form/dist/index.esm.js:256:37)
[1]     at form
[1]     at Styled.form
[1]     at main
[1]     at Styled.main
[1]     at div
[1]     at Styled.div
[1]     at observerComponent (webpack-internal:///../node_modules/mobx-react-lite/es/observer.js:49:73)
[1]     at observerComponent (webpack-internal:///../node_modules/mobx-react-lite/es/observer.js:49:73)
[1]     at Route (webpack-internal:///../node_modules/react-router/esm/react-router.js:464:29)
[1]     at Switch (webpack-internal:///../node_modules/react-router/esm/react-router.js:670:29)
[1]     at Routes (webpack-internal:///./renderer/Routes.tsx:67:76)
[1]     at Router (webpack-internal:///../node_modules/react-router/esm/react-router.js:93:30)
[1]     at HashRouter (webpack-internal:///../node_modules/react-router-dom/esm/react-router-dom.js:106:35)
[1]     at ExternalURLProvider (webpack-internal:///./utils/useExternalURL.tsx:29:3)
[1]     at APVSubscriptionProvider (webpack-internal:///./utils/APVSubscriptionProvider.tsx:24:3)
[1]     at StoreProvider (webpack-internal:///./utils/useStore.tsx:31:3)
[1]     at ApolloProvider (webpack-internal:///../node_modules/@apollo/client/react/context/ApolloProvider.js:12:21)
[1]     at LocaleProvider (webpack-internal:///./renderer/i18n/index.tsx:30:3)
[1]     at observerComponent (webpack-internal:///../node_modules/mobx-react-lite/es/observer.js:49:73)
Akamig commented 12 months ago

it was due to asynchronous logic in store initializer. resolved by https://github.com/planetarium/9c-launcher/pull/2346/commits/16cce2f15c3cbd845bf81f6098a24d436e038d8f