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

Local storage sometimes outdated without hard refresh. Should re-fetch all data if localStorage timestamp is older than server copy. #846

Closed
yuchant opened this issue May 16, 2018 · 5 comments

Comments

@yuchant
Copy link

yuchant commented May 16, 2018

🌈 Feature

I have been using codesandbox for only 30 hours, and have lost my changes numerous times due to completely accidental backwards swipes. I've rewritten quite a lot of code due to accidental back navigation.

This last instance felt like at least 3+ minutes of data lost.

Codesandbox should save unsaved history into local storage as much as possible. Not a true "save" but a state save.

If there are performance considerations on too many saves, it could be hooked into things like file selection, new tab selection, a long poll, or on the onbeforeunload event.

Thank you for your awesome work!

@yuchant yuchant changed the title Need partial save states saved to localStorage. It's too easy to accidentally navigate away from sandbox. Need partial unsaved state saved to localStorage. It's too easy to accidentally navigate away from sandbox and lose work. May 16, 2018
@yuchant
Copy link
Author

yuchant commented May 16, 2018

Actually, I think something else is going on with the back button.

I lost my work, started re-writing what I had lost, then tried to add a new file and got a Internal Server Error. I then refreshed, and got my original, unlost state back on reload.

This implies back->forward navigation is loading a stale state not from the server?

@yuchant
Copy link
Author

yuchant commented May 18, 2018

I've run into this problem several times now. It seems the app is prioritizing some old localStorage state even when remote is updated.

Each time I "lose" progress, I do a hard refresh and see my updated files.

Perhaps a timestamp check is in order on load where the localStorage can be compared to the live data + re-fetch if old? Optionally only if browser history is in latest state, though I question if being able to go "back" at all would ever make sense.

@yuchant yuchant changed the title Need partial unsaved state saved to localStorage. It's too easy to accidentally navigate away from sandbox and lose work. Local Storage sometimes outdated without hard refresh. Should re-fetch all data if localStorage timestamp is older than server copy. May 18, 2018
@yuchant yuchant changed the title Local Storage sometimes outdated without hard refresh. Should re-fetch all data if localStorage timestamp is older than server copy. Local storage sometimes outdated without hard refresh. Should re-fetch all data if localStorage timestamp is older than server copy. May 18, 2018
@CompuIves
Copy link
Member

Hmm, that is interesting. We don't put any files of the editor in the localStorage, we only do this for caches by our bundler.

This implies back->forward navigation is loading a stale state not from the server?

OH, I think that I know what it could be! Our Service Worker caches API responses, so if you load a sandbox without internet connection it will load the latest known version of the sandbox, which can be older. Hmm, yes, this is indeed bad behaviour, because it can behave flakey on bad connections. The best solution would be to save it in localStorage and do a timestamp comparison.

I'm not sure if I can get the time this week to work on it, but next week I can take a proper look!

@lbogdan
Copy link
Contributor

lbogdan commented Mar 28, 2019

Hey @yuchant ,

Is this still an issue for you?

@SaraVieira
Copy link
Contributor

Closed for lack of activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants