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

How to avoid loss of data when navigating away? #1797

Closed
tristan-orourke opened this issue Jan 19, 2022 · 3 comments · Fixed by #2183
Closed

How to avoid loss of data when navigating away? #1797

tristan-orourke opened this issue Jan 19, 2022 · 3 comments · Fixed by #2183
Assignees
Labels
spike Learn more about something we can't estimate yet.

Comments

@tristan-orourke
Copy link
Member

tristan-orourke commented Jan 19, 2022

Description

With a complicated form, we don't want users to accidentally navigate away from a half-finished form and lose a bunch of work.

Thoughts:

  • Can we easily intercept any navigation attempts and throw up a modal? Is that even good UI? Any accessibility concerns?
  • Can we cache half-complete forms instead? How? Browser localStorage? How much do we cache - just forms for new experience, or edits to existing ones? Does it have kind of expiration?
@tristan-orourke tristan-orourke added the spike Learn more about something we can't estimate yet. label Jan 19, 2022
@patcon
Copy link
Contributor

patcon commented Jan 19, 2022

Intercepting navigation feels like a heavy-handing strategy, but maybe easiest.

But for UX, I feel like this is a great place for a localstorage hook. Why make users read a popup when we can just save them from thinking :)

(not sure how bloated the packages are, so maybe best to homebrew the hook)

https://usehooks.com/useLocalStorage/
https://github.com/donavon/use-persisted-state
https://github.com/astoilkov/use-local-storage-state via donavon/use-persisted-state#36 (comment)

Re: autosave. Further, even if form data is persisted, hinting at this before the moment of panic is nice. To avoid the brief "oh shit!" feeling of accidentally leaving, there's room for an autosave UI patterns to let people know that their fields are immediately saved (e.g., checkmark flash beside field onBlur).

Important consideration it to make sure people don't assume data is automatically submitted just because it is persisting. Good to be clear that submission is still required, even once they know the data seems to be "saved".

@tristan-orourke
Copy link
Member Author

@patcon I like that useHooks library! I think I've basically written some of those myself before.

@JoshBeveridge there's some UX consideration to be had here.

@JoshBeveridge
Copy link
Member

@tristan-orourke and I chatted this through, and I think having both a native browser alert AND caching is the ideal situation, but we can settle for caching first if that's going to handle a majority of users. Tristan thinks you might have to listen for the navigation event anyway, so implementing either will require checking for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spike Learn more about something we can't estimate yet.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants