hypothesis / h

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

Avoid warning when creating a new group #8900

Closed acelaya closed 1 month ago

acelaya commented 1 month ago

useWarnOnPageUnload is causing a native warning to be displayed after a group has been created, because we do a synchronous redirect via window.location.href = ... as part of the form's onSubmit.

The same callback also updates a piece of state that should avoid that warning, but the state is not synced in time.

This PR avoids a synchronous redirect, and instead adds a second piece of state which holds the location to redirect to. Then using useEffect we do the redirection once that state has been set.

acelaya commented 1 month ago

Close in favor of https://github.com/hypothesis/h/pull/8901