Skip to content

fix: an expired IAP sign-in reloads the page instead of failing every background request - #125

Merged
fiddur merged 3 commits into
developfrom
iap-reauth-refresh
Nov 10, 2026
Merged

fiddur merged 3 commits into
developfrom
iap-reauth-refresh

Conversation

@fiddur

@fiddur fiddur commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Background requests on the Sessions and review pages detect IAP's sign-in redirect (redirect: 'manual'). The page reloads once when the tab is visible and nothing typed would be lost; otherwise it says to reload.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

… background request

Background requests use redirect: 'manual', so IAP's redirect to Google is seen as a sign-out. The page
reloads once when nothing would be lost, and otherwise says to reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w
@fiddur
fiddur requested a balanced review from Copilot November 10, 2026 08:35

@diffity diffity Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found. Checked that every UI fetch goes through apiRequest, that no /s//api route redirects on its own (signed-out answers 401), that an automatic reload never happens with a typed draft, a focused field or a hidden tab, and that the Sessions page retries the reload when its tab becomes visible again. Any text input with a value (a filter box too) blocks the automatic reload; the banner covers that case.

— diffity review, requested by @fiddur

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Authentication handling misses HTTP 401 responses, and the reload guard can discard unsaved comment edits when a save request redirects to sign-in.

2 open issues
What changed in this PR

This PR adds recovery from expired IAP sign-ins to the Sessions and review pages, replacing repeated background-request failures with a guarded reload or a sign-in notice.

Changes:

  • Detect authentication redirects in shared UI requests and Sessions polling.
  • Attempt automatic reloads when the page is visible and editing safeguards allow them; otherwise offer manual recovery.
  • Add tests for redirect detection, reload guards, and signed-out notices.
File Description
packages/​ui/​tests/​sign-in.test.tsx Tests request handling, reload guards, and banner rendering.
packages/​ui/​src/​root.tsx Mounts the signed-out banner.
packages/​ui/​src/​lib/​sign-in.ts Tracks signed-out state and guards automatic reloads.
packages/​ui/​src/​lib/​request.ts Adds shared authentication-redirect detection.
packages/​ui/​src/​lib/​api.ts Routes API requests through the new helper.
packages/​ui/​src/​hooks/​use-tab-badge.ts Uses the helper when fetching the favicon.
packages/​ui/​src/​components/​layout/​signed-out-banner.tsx Displays recovery controls and attempts safe reloads.
packages/​server/​tests/​http.test.ts Checks Sessions sign-out handling and notice markup.
packages/​server/​src/​html.ts Adds Sessions authentication detection and reload recovery.

Review effort: Balanced

Comment thread packages/ui/src/lib/request.ts Resolved
Comment thread packages/ui/src/lib/sign-in.ts Resolved
… page on its own

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Pending saves remain unprotected until their responses arrive, allowing an authentication-triggered reload to discard unsaved edits while a PATCH is still in flight.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread packages/ui/src/lib/request.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A failed comment save clears reload protection while unsaved text remains hidden in React state, allowing a later sign-out-triggered reload to discard the edit.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Failed comment saves can allow reloads to discard unsaved edits

packages/​ui/​src/​lib/​request.ts:22

If a comment save returns HTTP 500 or rejects with a network error, this finally clears its reload protection even though CommentBubble.handleSave() has hidden the editor and retained the unsaved text in React state. A later background request detecting sign-out can then trigger an automatic reload and discard that edit. Track unsuccessful writes separately from authentication state so they continue to block automatic reload, or keep the editor visible until saving succeeds.

2 resolved since last review

Review effort: Balanced

@fiddur
fiddur marked this pull request as ready for review November 10, 2026 08:54
@fiddur
fiddur merged commit 87450ec into develop Nov 10, 2026
2 checks passed
@fiddur
fiddur deleted the iap-reauth-refresh branch November 10, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants