Persisted form state with sessionStorage#1522
Conversation
|
Cool idea. We have to be careful because this is where the console starts to cross the line into being an application rather than a client to the real application, which is Nexus. To me that means trying to make it as clear as possible what the logic around peristence is. My main concern is about persisting too much or too often. I like the idea behind the 5 minute timeout, but I could see someone coming to expect it to be longer, maybe arbitrary length, just because they’ve never gone longer than 5 minutes, and then being pretty upset when they left it longer and something they wrote out disappeared. I wonder if we should have a clear form button. With RHF that should be very easy, just call reset() on click. |
|
Good points — I feel like it's worthwhile persisting for smaller forms (namely just the side modal ones) and not the full page forms. The stakes are pretty low for those, that way there's a convenience but it's not significant if you were to lose it. We could also drop the timeout and just let the expiration of Full page forms i'm less sold on, I think a |
|
Yeah, this is neat. Something I think could be beneficial is to be very explicit about what we're doing and why. In this case (closing a halfway completed side modal) we could pop open a toast saying something along the lines of "we've temporarily saved your work" with a link to the docs and perhaps and option to clear. I'm not sure if that would be too much, the point being here is that we're just really explicit about what's happening and why. We've put a lot of effort into other areas of the product to give that same sort of clarity. |
|
Let me give that some thought — also took a stab at #1523 just because, but happy to leave that and get this implemented on full page forms also. Toasts do feel too intrusive for this use case, so I'll consider if there's something else that might work. Likewise for a form reset. There might be a pattern that asks you if you want to continue where you left off when you open the form. |
Yeah, I think no expiration and using sessionStorage’s own scoping/expiration logic is probably the most legible/predictable option. |
|
I'm still thinking on this. I think the thing I really want to see from whatever solution we come up with is for the user to have explicit acknowledgement of whatever is happening. As much as possible I want to reduce unexplained, automatic behavior. I really don't want user's to be asking themselves "wtf just happened?" Granted, I know for forms auto filling that's less of a big deal, but still.
I think this would be even better. A mechanism to opt-in to restore a session instead of it automatically happening. The only challenge here is the user may not remember what was automatically persisted from the last session. We could allow them to fill it in and give them an option to clear it. I'm not sure. Worth some extra thought though. I'm not against this being merged as is necessarily nor do I want to overburden the UI. We could always land this and iterate on how it feels to us and the team. |
|
Any thoughts on either of these approaches? @david-crespo @zephraph |
|
Given the two, I think I'd got for opt-out. In that case you're able to see what's there before making a decision. In the opt-in case, you don't know what values you're opting into. |
|
Another potential consideration: we're likely going to want to announce to a screen reader what's happening in each case. For a sighted user it's easy to scan the form quickly. Well, thinking more about that, I think it would be the same UX either way, so it's no big deal. That doesn't need to implemented in this PR, but it'd be good to have an issue to track it. |
|
Great feedback! I've implemented both of those. Last thing on my list is updating |
|
Ready to go now |
|
This looks good to me. It wouldn't hurt for us to follow up with some E2E tests just to exercise a few different scenarios to ensure we don't accidentally break it in the future. Otherwise, great job @benjaminleonard! |
| variant="info" | ||
| content={ | ||
| <div className="flex items-center justify-between"> | ||
| <div>Restored previous session</div> |
There was a problem hiding this comment.
I think this is confusing copy. "Session" gives it too much weight as a concept, and it makes it sound like a unified thing rather than bits of state per-form. I think something really concrete and flat like "Restored form state" would be better. There's still the question "from where?" when you see that — maybe the icon should be a hover tooltip that says something to the effect of "We will keep the contents of an incomplete form around until you clear it or close the tab or window"
There was a problem hiding this comment.
Made the copy change, let me think about the tooltip, since it'd require breaking the message component out for this use one case.
…computer/console into form-local-storage-persist
ced2027 to
6e4f098
Compare
|
We talked about this a little in chat, but I want to put this on hold. There are a few issues that might not be that bad to fix, but they do add up, and since this to me is a nice-to-have, I don't think it's worth the time right now, and more importantly, it puts a burden on us in perpetuity to make sure forms remain compatible with the persistence mechanism. Failure to do so can manifest in weird ways that are hard to notice. Why only nice-to-haveYou compare this to text field restoration on GitHub issues, but most of the time, I don't think filling out a form is much like writing out a comment or PR description. Writing can have an arbitrary amount of texture and detail to it, and when you lose something you've written that can be very frustrating. I could certainly be convinced otherwise, but I doubt the same is true of most of our forms, which are 4-8 fields of structured data. We have few big text fields and I don't see people sitting there thoughtfully composing their disk description with reference to a bunch of other browser tabs. Alternate approachesI experimented with using Issues I found
|



Whilst taking a look at
useBlocker/usePrompt— I thought that in most cases it's probably preferable to instead hang on to the form state after clicking off and returning to the form rather than blocking navigation. GitHub does this with issues and it's really useful.It's pretty simple to do. We get the values form the form, turn them into a JSON object, add to
sessionStorageusing the forms ID as a key. Then whenever we go back to the form we look up with that same key, check that it's not older than 5 minutes (bit of an arbitrary value I picked) and retrieve it, looping over the values and setting them on the form. When a form is submitted the state is cleared.Some limitations —
Doesn't currently handle nested values likeblockSizebut I don't think this is too complicated to supportSideModalForm