do not render the frame before its session exists

Saving the connection showed an error that a refresh then cleared. The effect
that re-mints the frame session re-ran, but `state` was left at 'ready' from
the previous pass — so the iframe mounted immediately, before the cookie
existed, and the first request inside it answered 401. By the time anyone
refreshed, the mint had finished.

A stale 'ready' is worse than a spinner: it renders something broken
confidently.

Also stays on the form after the URL-only step, where there is still a token to
set. Bouncing to a frame that immediately sends you back is worse than not
moving.
This commit is contained in:
officer
2026-08-19 10:45:05 +00:00
parent 39f2d0c7ed
commit e820831aec
2 changed files with 16 additions and 1 deletions
+7 -1
View File
@@ -81,10 +81,16 @@ export const GiteaConnection = ({ state, onSaved }: Props) => {
setError(null);
try {
await put('/gitea/_config', state.isOwner === false ? { token } : { url, token });
// ORDER MATTERS. `onSaved` re-reads the connection and re-mints the frame session; navigating
// first would swap to the frame while that is still in flight, and the frame would load against a
// session that does not exist yet.
onSaved();
// Back to the frame. Saving from `/gitea/connection` otherwise leaves you looking at the form you
// just submitted, which reads as nothing having happened.
navigate('/gitea');
//
// Only when there is a frame to go back TO: after the URL-only step there is still a token to
// set, and bouncing to a frame that immediately sends you back is worse than staying put.
if (!needsUrl) navigate('/gitea');
} catch (err) {
setError(err instanceof Error ? err.message : 'could not save');
} finally {