Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/main/windows/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ export function createWindow(options?: { chatId?: string; subChatId?: string }):
partition: "persist:main", // Use persistent session for cookies
},
})
let attemptedRendererRecovery = false

// Register window with manager and get stable ID for localStorage namespacing
const stableWindowId = windowManager.register(window)
Expand Down Expand Up @@ -741,6 +742,22 @@ export function createWindow(options?: { chatId?: string; subChatId?: string }):
return { action: "deny" }
})

window.webContents.on("render-process-gone", (_event, details) => {
console.error("[Main] Renderer process gone in window", window.id, details)

if (attemptedRendererRecovery || window.isDestroyed()) {
return
}

attemptedRendererRecovery = true
setTimeout(() => {
if (!window.isDestroyed()) {
console.log("[Main] Attempting one-shot renderer recovery in window", window.id)
window.webContents.reloadIgnoringCache()
}
}, 150)
})

// Prevent window close if there are active streaming sessions
window.on("close", (event) => {
// Skip confirmation if app quit was already confirmed by the user
Expand Down Expand Up @@ -835,6 +852,7 @@ export function createWindow(options?: { chatId?: string; subChatId?: string }):

// Log page load - traffic light visibility is managed by the renderer
window.webContents.on("did-finish-load", () => {
attemptedRendererRecovery = false
console.log("[Main] Page finished loading in window", window.id)
})
window.webContents.on(
Expand Down
90 changes: 76 additions & 14 deletions src/renderer/components/ui/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { Component, type ReactNode } from "react"
import { AlertCircle } from "lucide-react"
import { Button } from "./button"

interface RenderErrorBoundaryProps {
children: ReactNode
title?: string
description?: string
resetKey?: string | number | null
onReset?: () => void
compact?: boolean
showReload?: boolean
}

interface ErrorBoundaryProps {
children: ReactNode
viewerType?: string
Expand All @@ -13,11 +23,11 @@ interface ErrorBoundaryState {
error: Error | null
}

export class ViewerErrorBoundary extends Component<
ErrorBoundaryProps,
export class RenderErrorBoundary extends Component<
RenderErrorBoundaryProps,
ErrorBoundaryState
> {
constructor(props: ErrorBoundaryProps) {
constructor(props: RenderErrorBoundaryProps) {
super(props)
this.state = { hasError: false, error: null }
}
Expand All @@ -28,35 +38,87 @@ export class ViewerErrorBoundary extends Component<

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error(
`[ViewerErrorBoundary] ${this.props.viewerType || "viewer"} crashed:`,
`[RenderErrorBoundary] ${this.props.title || "section"} crashed:`,
error,
errorInfo,
)
}

componentDidUpdate(prevProps: RenderErrorBoundaryProps) {
if (
this.state.hasError &&
prevProps.resetKey !== this.props.resetKey
) {
this.setState({ hasError: false, error: null })
}
}

handleReset = () => {
this.setState({ hasError: false, error: null })
this.props.onReset?.()
}

handleReload = () => {
window.location.reload()
}

render() {
if (this.state.hasError) {
return (
<div className="flex flex-col items-center justify-center h-full gap-3 p-4 text-center">
<div
className={
this.props.compact
? "flex h-full flex-col items-center justify-center gap-3 p-4 text-center"
: "flex h-full min-h-0 w-full flex-col items-center justify-center gap-4 p-6 text-center"
}
>
<AlertCircle className="h-10 w-10 text-muted-foreground" />
<p className="font-medium text-foreground">
Failed to render {this.props.viewerType || "file"}
</p>
<p className="text-sm text-muted-foreground max-w-[300px]">
{this.state.error?.message || "An unexpected error occurred."}
</p>
<Button variant="outline" size="sm" onClick={this.handleReset}>
Try again
</Button>
<div className="space-y-1">
<p className="font-medium text-foreground">
{this.props.title || "Something went wrong"}
</p>
<p className="text-sm text-muted-foreground max-w-[420px]">
{this.props.description ||
this.state.error?.message ||
"An unexpected error occurred."}
</p>
{this.props.description && this.state.error?.message && (
<p className="text-xs text-muted-foreground/70 max-w-[420px] break-words">
{this.state.error.message}
</p>
)}
</div>
<div className="flex items-center gap-2">
<Button variant="outline" size="sm" onClick={this.handleReset}>
Try again
</Button>
{this.props.showReload !== false && (
<Button variant="outline" size="sm" onClick={this.handleReload}>
Reload window
</Button>
)}
</div>
</div>
)
}

return this.props.children
}
}

export function ViewerErrorBoundary({
children,
viewerType,
onReset,
}: ErrorBoundaryProps) {
return (
<RenderErrorBoundary
title={`Failed to render ${viewerType || "file"}`}
onReset={onReset}
compact
showReload={false}
>
{children}
</RenderErrorBoundary>
)
}
Loading