Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make useStorage hooks more reliable (probably) #55

Merged
merged 8 commits into from
Sep 22, 2023
Merged

Conversation

emlun
Copy link
Member

@emlun emlun commented Sep 21, 2023

We've seen problems with the login procedure sometimes failing to set privateData in local storage. This seems to be because the internal useState hook sometimes fails to update currentValue even though setValue() was called. This made the internal useEffect hook fail to write the new value into local storage, and also made the new state fail to propagate to other instances of the useStorage hook.

I don't know why this happens, but these changes refactor the data flow such that the public setter function always writes to local (or session) storage and then notifies other useStorage instances with the same name. This seems to make the login procedure reliably set privateData successfully.

I have seen some issues with this too, namely that the login procedure would hang on the eDiplomas spinner and not move on to the logged-in view. However, this only happened when I had some console.log statememts throughout the hooks for debugging. I have not seen the issue without these console.log statements, so I hope this is fine? Anyway, just so you know in case that issue returns.

Also don't fall back to plain global state for session storage when session
storage is not available. The caller may rightly assume that session state
persists across page reloads, which plain global state does not.
@gkatrakazas
Copy link
Contributor

Great! Look like it's working, we are testing it a bit more and we will merge it.

@emlun
Copy link
Member Author

emlun commented Sep 22, 2023

I've been digging more into the issue of hanging on the spinner, and it seems I can still reproduce it fairly reliably by

  1. Log out
  2. Press Ctrl+Shift+R to force-reload the page
  3. Log in

This still results in hanging on the spinner fairly often. But I think this might have to do with other state management throughout the app. 🙂 I've noticed that handleServerMessagesGuard tends to open multiple sockets and sometimes fails to initialize, which results in hanging on the spinner. But after I restructured that code to be more reliable using hooks, the app would instead still show the login form even after successful login (reloading the page shows the logged-in view though, indicating it's a frontend state issue). I can't tell what causes this - <Api>, <Login> and <Notification> both re-render, but neither <PrivateRoute> nor <Home> ever even attempts to render. In fact it seems like the router still has /login as the current location even after <Login> calls navigate('/'). 😕

@gkatrakazas
Copy link
Contributor

I believe the spinner issue might be resolved with this commit: gunet@ffd6535

@emlun
Copy link
Member Author

emlun commented Sep 22, 2023

Cool!

@gkatrakazas gkatrakazas merged commit bcc7816 into master Sep 22, 2023
0 of 2 checks passed
@emlun emlun deleted the reliable-storage branch September 22, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants