Skip to content

An open-source, faster Devin alternative

TypeScript

fix(web): review round 4 — org-state isolation, key-create gate, polish

Igor Zalutski8e383bbf3c64
diff --git a/web/src/api/client.ts b/web/src/api/client.ts
index 578d8d9c..545f2676 100644
--- a/web/src/api/client.ts
+++ b/web/src/api/client.ts
@@ -204,6 +204,9 @@ export interface LogEvent {
command?: string
argv?: string[]
exit_code?: number
+ // Client-assigned monotonic ingest order. Not from the API — set on parse so
+ // the live list has a stable React key under filtering + cap trimming.
+ _seq?: number
}
export interface LogStreamOptions {
diff --git a/web/src/components/LogsPanel.tsx b/web/src/components/LogsPanel.tsx
index 351afd61..f769317f 100644
--- a/web/src/components/LogsPanel.tsx
+++ b/web/src/components/LogsPanel.tsx
@@ -72,6 +72,7 @@ export default function LogsPanel({ sandboxId, onClose }: LogsPanelProps) {
// Buffered events that arrived while paused; flushed on resume.
const pausedBufRef = useRef<LogEvent[]>([])
+ const seqRef = useRef(0)
const containerRef = useRef<HTMLDivElement | null>(null)
const stickToBottomRef = useRef(true)
@@ -108,6 +109,7 @@ export default function LogsPanel({ sandboxId, onClose }: LogsPanelProps) {
} catch {
return
}
+ ev._seq = seqRef.current++
if (pausedRef.current) {
pausedBufRef.current.push(ev)
// Defensive cap on the paused buffer.
@@ -300,8 +302,8 @@ export default function LogsPanel({ sandboxId, onClose }: LogsPanelProps) {
this deployment.
</div>
) : null}
- {visible.map((ev, i) => (
- <Row key={i} ev={ev} />
+ {visible.map((ev) => (
+ <Row key={ev._seq} ev={ev} />
))}
</div>
diff --git a/web/src/components/app-shell.tsx b/web/src/components/app-shell.tsx
index 4383a797..762ffd5b 100644
--- a/web/src/components/app-shell.tsx
+++ b/web/src/components/app-shell.tsx
@@ -60,6 +60,7 @@ function Brand() {
function OrgSwitcher() {
const { user, switchOrg } = useAuth()
+ const [switching, setSwitching] = useState(false)
const orgs = user?.orgs ?? []
if (orgs.length <= 1) return null
const active = orgs.find((o) => o.isActive)
@@ -71,6 +72,7 @@ function OrgSwitcher() {
variant="outline"
className="w-full justify-between font-normal"
size="sm"
+ disabled={switching}
>
<span className="truncate">{active?.name || 'Select org'}</span>
<ChevronsUpDown className="size-3.5 shrink-0 opacity-60" />
@@ -86,7 +88,9 @@ function OrgSwitcher() {
<DropdownMenuItem
key={org.id}
onClick={() => {
- if (!org.isActive) void switchOrg(org.id)
+ if (org.isActive || switching) return
+ setSwitching(true)
+ void switchOrg(org.id).finally(() => setSwitching(false))
}}
className="gap-2"
>
@@ -196,6 +200,7 @@ function HaltBanner() {
}
export default function AppShell() {
+ const { user } = useAuth()
const [drawerOpen, setDrawerOpen] = useState(false)
const location = useLocation()
@@ -240,8 +245,10 @@ export default function AppShell() {
<div className="md:pt-16 md:pl-60">
<HaltBanner />
<main className="mx-auto max-w-7xl px-4 py-6 sm:px-8">
- {/* Keyed by route so a page error clears when you navigate away. */}
- <ErrorBoundary key={location.pathname}>
+ {/* Keyed by org + route: clears a page error on navigation AND
+ remounts org-scoped pages on org switch so local draft/filter
+ state can't bleed across orgs. */}
+ <ErrorBoundary key={`${user?.orgId ?? ''}:${location.pathname}`}>
<Suspense
fallback={
<div className="flex min-h-[60vh] items-center justify-center">
diff --git a/web/src/components/copy-row.tsx b/web/src/components/copy-row.tsx
index 69436154..fd625aba 100644
--- a/web/src/components/copy-row.tsx
+++ b/web/src/components/copy-row.tsx
@@ -2,6 +2,7 @@ import { useState } from 'react'
import { Check, Copy, Eye, EyeOff } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { useTransientFlag } from '@/lib/use-transient-flag'
+import { notifyError } from '@/lib/errors'
import { cn } from '@/lib/utils'
/**
@@ -29,8 +30,12 @@ export function CopyRow({
const copyText = transform ? transform(value) : value
const copy = () => {
- void navigator.clipboard.writeText(copyText)
- markCopied()
+ // Only show "Copied" if the write actually succeeds (clipboard can be
+ // blocked by permissions / insecure context).
+ void navigator.clipboard.writeText(copyText).then(
+ () => markCopied(),
+ (e: unknown) => notifyError("Couldn't copy to clipboard.", e),
+ )
}
return (
diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx
index f2107ff6..a6200692 100644
--- a/web/src/pages/Dashboard.tsx
+++ b/web/src/pages/Dashboard.tsx
@@ -217,7 +217,11 @@ function SandboxRow({ session }: { session: Session }) {
/* ── First-run onboarding ─────────────────────────────────────────────────── */
function GettingStarted() {
const queryClient = useQueryClient()
- const { data: keys, isLoading: loadingKeys } = useQuery({
+ const {
+ data: keys,
+ isLoading: loadingKeys,
+ isSuccess: keysLoaded,
+ } = useQuery({
queryKey: ['api-keys'],
queryFn: getAPIKeys,
})
@@ -234,12 +238,14 @@ function GettingStarted() {
// On first signup (no keys), auto-create a Default key so the user sees it
// immediately without clicking anything.
useEffect(() => {
- if (loadingKeys || autoCreateRef.current) return
+ // Only auto-create after a SUCCESSFUL (empty) keys list — never after the
+ // list errored (keys would be undefined → falsely "no keys").
+ if (!keysLoaded || autoCreateRef.current) return
if (!hasKeys && !createdKey && !createMutation.isPending) {
autoCreateRef.current = true
createMutation.mutate()
}
- }, [loadingKeys, hasKeys, createdKey, createMutation])
+ }, [keysLoaded, hasKeys, createdKey, createMutation])
return (
<div className="space-y-4">
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SessionDetail.tsx
index 53b60424..b5a8506d 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SessionDetail.tsx
@@ -1,4 +1,4 @@
-import { lazy, Suspense, useState } from 'react'
+import { lazy, Suspense, useEffect, useRef, useState } from 'react'
import { Link, useNavigate, useParams } from 'react-router-dom'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { notifyError } from '@/lib/errors'
@@ -123,10 +123,23 @@ export default function SessionDetail() {
onSettled: invalidate,
})
+ const copyTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
+ useEffect(
+ () => () => {
+ if (copyTimer.current) clearTimeout(copyTimer.current)
+ },
+ [],
+ )
+
const copyUrl = (hostname: string, key: string) => {
- void navigator.clipboard.writeText(`https://${hostname}`)
- setCopiedUrl(key)
- setTimeout(() => setCopiedUrl(null), 2000)
+ void navigator.clipboard.writeText(`https://${hostname}`).then(
+ () => {
+ setCopiedUrl(key)
+ if (copyTimer.current) clearTimeout(copyTimer.current)
+ copyTimer.current = setTimeout(() => setCopiedUrl(null), 2000)
+ },
+ (e: unknown) => notifyError("Couldn't copy to clipboard.", e),
+ )
}
if (isLoading) {