hypothesis / h

Annotate with anyone, anywhere.
https://hypothes.is/
BSD 2-Clause "Simplified" License
2.96k stars 427 forks source link

Warn when a client-side navigation will lose changes #9098

Closed robertknight closed 3 days ago

robertknight commented 4 days ago

Add infrastructure to register when a component has unsaved changes and show a confirmation dialog upon a client-side navigation in this case. Use this infrastructure to show a confirmation dialog when attempting to navigate from the "Settings" tab to the "Members" tab if there are unsaved changes.

Client-side leave warning

Fixes https://github.com/hypothesis/h/issues/9096.


Testing:

  1. Go to the edit page for a group
  2. Navigate between the Settings and Members tab, or to a different URL. There should be no confirmation.
  3. Change one of the fields in the Settings tab but don't save.
  4. Click the Members tab, you should see a confirmation dialog. Clicking "Leave page" / Cancel should confirm or cancel the navigation respectively.
  5. Navigate to a different site when there are unsaved changes in the Settings tab. You should see the browser's warning about unsaved changes.

Implementation notes:

The implementation uses Wouter's API for customizing the location hook that is used by links that perform client-side navigations.