getodk / getodk/central

Alert user navigating away during non-GET request

Open
#1,296 1 comment 0 reactions 0 assignees View on GitHub
frontend
Dominant language
JavaScript
Stars
226
Forks
235
Avg merge
2d 22h
Merged PRs (30d)
19

Description

Right now, if the user triggers a request, then navigates to a new route before the response is received, Frontend will ignore the response. However, especially if a non-GET request is sent, that means that the state of Frontend might no longer reflect Backend. For example:

- Navigate to the project settings page.
- Enter a new project name, then click "Save settings".
- Before the response is received, navigate to the project overview.
- Even after the response is received, the new project name is not shown in the project overview. If you navigate back to project settings, the old project name is shown in the "Project name" field.

I think this is actually roughly the behavior we want. Using the response possibly well after the user has navigated away could lead to complexity and possibly surprising behavior.

However, I think it'd also be useful to alert the user before they navigate away. I think we could use the existing `unsavedChanges` mechanism for this: if the `unsavedChanges` flag is set, then if the user tries to navigate away, they are first alerted that there are unsaved changes.

I think the main piece of this is that the `request` mixin would set `unsavedChanges` when it sends the request, then unset it after the response is received (or there is an error).

One complication is that concurrent non-GET requests are possible. For example, changing the roles of multiple users in the users table will send a request for each user. Given that, we would probably want to change `unsavedChanges` from a boolean to a number. In that case, the `request` mixin would increment `unsavedChanges` when it sends each request, then decrement it after each response (or error).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.