Skip to content

fix(web): unify API fetch, add error boundaries and route splitting, and clean types - #1854

Merged
nikhilunni merged 5 commits into
mainfrom
audit/p2-web-quality
Dec 2, 2026
Merged

nikhilunni merged 5 commits into
mainfrom
audit/p2-web-quality

Conversation

@nikhilunni

@nikhilunni nikhilunni commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Improves web/ reliability, bundle splitting, API consistency, and type safety:

  • Unified API fetch: Replaces three duplicated request<T> helpers (all of which clobbered Accept: application/json when init.headers was passed) and ad-hoc fetch calls with a single api-fetch.ts helper respecting API_CREDENTIALS, plus a shared useAuthConfig() hook. An error message is the server's text when it is short (300 characters or fewer), else the status line, as the credentials helper did. A 204 resolves to undefined for every caller.
  • Error boundaries & fallbacks: Adds reusable React ErrorBoundary wrapping the app and heavy interactive panes (keyed by session, spec, or automation so a new page starts clean), and configures defaultErrorComponent and defaultNotFoundComponent on TanStack Router.
  • Route code splitting: Converts every leaf page route to lazyRouteComponent (layout routes, the start screen, and the login page stay in the main bundle). lazyRouteComponent reloads the page once when a chunk is missing after a deploy.
  • Terminal reconnect & cleanup: Adds bounded exponential-backoff reconnect (5 tries, 0.5 s to 8 s; budget resets after 30 s connected) on transport drops (1001/1005/1006/1011/1012/1013) in TerminalPane. A normal close, a refusal, or unmount does not reconnect. ttyd starts a new shell for each connection, so the pane writes a marker line where the new shell starts. Removes any escapes in RegistriesPanel.tsx and useEnableJobs.ts, and deletes stale tracked web/bun.lock.

Behavior note

Opening the shell resumes an idle session and pins it against idle eviction (coordinator ShellRelay). The work pane keeps the terminal mounted while it is hidden, so the terminal reconnects only while it is shown: a drop while the shell tab or the pane is hidden waits, and the terminal reconnects when it is shown again, with the same retry budget. A hidden tab never resumes an evicted session. A drop while the terminal is shown reconnects after the backoff, at most 5 times.

Validation

  • pnpm format:check: passed.
  • pnpm lint: passed.
  • pnpm test: passed (one unrelated Mermaid render test timed out under machine load and passes alone).
  • pnpm build: passed with separate chunks emitted for the lazy routes.

🤖 Generated with Claude Code

nikhilunni and others added 5 commits December 1, 2026 11:59
The credentials helper showed the server's text only when it was short,
so a proxy's HTML error page fell back to the status line. The shared
helper lost that cap and showed any body in full. Trim the detail and
use the status line when it is empty or longer than 300 characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ttyd starts a new shell for each connection. An automatic reconnect
keeps the old screen, so the new prompt appeared below the output of a
shell that no longer exists. Write a dim marker line where the new
shell starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st facts

Review pass over the files this change touched:
- base.ts: the header lost what a split-host deployment needs (the
  injected origin, TRUSTED_ORIGINS, the shared cookie domain). State it
  again in a short form.
- useHarnessEnv, SpecShellPage: apiFetch already sends the JSON Accept
  header, so remove the copies.
- router.tsx, AutomationEditor, useApps, useIntegrations: move the new
  imports into the import block (one sat above the file header).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening the shell resumes an idle session. The work pane keeps the
terminal mounted when it is hidden, so an automatic reconnect from a
hidden pane could resume a session that was just evicted. A drop while
hidden now waits, and the pane reconnects when it is shown again, with
the same retry budget. A retry that is pending when the pane is hidden
also waits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikhilunni
nikhilunni marked this pull request as ready for review December 2, 2026 21:53
@nikhilunni
nikhilunni merged commit 5edf521 into main Dec 2, 2026
28 checks passed
@nikhilunni
nikhilunni deleted the audit/p2-web-quality branch December 2, 2026 21:53
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.

1 participant