Desktop: never a blank window (frozen-prototype fix, error screens, logs, state migration, boot check)
The signed release showed only its background colour and never started the sidecar. Tauri's freezePrototype freezes Object.prototype before the bundle runs; d3-color and d3-format (under the visx charts) assign `constructor` / `toString` on plain objects while loading, which throws on a frozen prototype, so the bundle stopped before React drew anything. The saved state was not the cause. - build/freeze-safe.ts: Vite plugin that rewrites those assignments in dependencies into a helper that defines the property when the frozen prototype would refuse it - error boundaries for the window, each screen and each app tab (Copy details, Reload, Reset saved state with a backup); public/boot.js shows the same panel when the bundle fails or the window stays empty - logs/host.log (start, saved state, sidecar start/stop, panics) and logs/webview.log (log_webview), rotated, home as ~, keys, tokens and e-mail addresses replaced - state.json `version` 2 with an explicit 1 -> 2 migration (original kept as state.json.v1.bak), per-entry tolerant parsing, partial settings keep their fields, unreadable files kept aside - folders that are gone: "Folder not found" with Locate... (project_locate) / Remove; portfolio reads skip them - tools/desktop-boot-check.ts: the built window with the release CSP and the frozen prototype, a mocked host from the state fixtures (empty, D1 with folders gone, D3) and the real sidecar, through every screen; in bun run ci, the Forgejo CI workflow and the macOS release
This commit is contained in:
parent
209b8d0559
commit
08eb314196
45 changed files with 2080 additions and 69 deletions
61
apps/desktop/src/ui/ErrorBoundary.tsx
Normal file
61
apps/desktop/src/ui/ErrorBoundary.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// Error boundaries: a render error shows what failed and the ways out (Copy details, Reload, Reset saved state with a
|
||||
// backup) instead of an empty window. One wraps the whole app (`full`), one each screen and app tab, so a broken
|
||||
// screen leaves the sidebar and the other screens working. The fallback uses plain elements only: it must not fail
|
||||
// the way the screen did.
|
||||
import { Component, type ErrorInfo, type ReactNode, useState } from 'react';
|
||||
import { api, errorText } from '../api';
|
||||
import { t } from '../i18n';
|
||||
import { type CrashReport, copyText, describe, report } from '../lib/crash';
|
||||
|
||||
interface Props { where: string; full?: boolean; children: ReactNode }
|
||||
interface State { error: unknown; info: CrashReport | null }
|
||||
|
||||
export class ErrorBoundary extends Component<Props, State> {
|
||||
override state: State = { error: null, info: null };
|
||||
|
||||
static getDerivedStateFromError(error: unknown): Partial<State> {
|
||||
return { error: error ?? new Error('unknown error') };
|
||||
}
|
||||
|
||||
override componentDidCatch(error: unknown, info: ErrorInfo): void {
|
||||
this.setState({ info: report(this.props.where, error, info.componentStack) });
|
||||
}
|
||||
|
||||
override render(): ReactNode {
|
||||
if (this.state.error === null) return this.props.children;
|
||||
const info = this.state.info ?? describe(this.props.where, this.state.error);
|
||||
return <CrashPanel where={this.props.where} full={!!this.props.full} info={info} onRetry={this.props.full ? undefined : () => this.setState({ error: null, info: null })} />;
|
||||
}
|
||||
}
|
||||
|
||||
export function CrashPanel({ where, full, info, onRetry }: { where: string; full: boolean; info: CrashReport; onRetry?: () => void }) {
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
const copy = async () => setNote((await copyText(info.detail)) ? t('crash.copied') : t('crash.copyFailed'));
|
||||
const reset = async () => {
|
||||
try {
|
||||
const backup = await api.resetState();
|
||||
if (backup !== null) { setNote(t('crash.resetDone', { path: backup || '-' })); setTimeout(() => location.reload(), 1200); }
|
||||
} catch (e) { setNote(errorText(e)); }
|
||||
};
|
||||
return (
|
||||
<div className={full ? 'crash crash-full' : 'crash'} role="alert" data-crash={where}>
|
||||
<div className="crash-box">
|
||||
<h2>{full ? t('crash.titleApp') : t('crash.titleScreen')}</h2>
|
||||
<p>{full ? t('crash.leadApp') : t('crash.leadScreen')}</p>
|
||||
<pre className="crash-msg selectable">{info.message}</pre>
|
||||
<details>
|
||||
<summary>{t('crash.details')}</summary>
|
||||
<pre className="crash-detail selectable">{info.detail}</pre>
|
||||
</details>
|
||||
<div className="actions">
|
||||
<button className="btn" onClick={copy}>{t('crash.copy')}</button>
|
||||
{onRetry && <button className="btn" onClick={onRetry}>{t('crash.retry')}</button>}
|
||||
<button className="btn btn-primary" onClick={() => location.reload()}>{t('crash.reload')}</button>
|
||||
<button className="btn btn-ghost" onClick={reset} title={t('crash.resetHint')}>{t('crash.reset')}</button>
|
||||
</div>
|
||||
{note && <p className="small muted" role="status">{note}</p>}
|
||||
<p className="small muted">{t('crash.logNote')}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
42
apps/desktop/src/ui/FolderMissing.tsx
Normal file
42
apps/desktop/src/ui/FolderMissing.tsx
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// An app folder that is gone (moved, renamed, deleted, or an old worktree): say so, and offer Locate… (keeps the app's
|
||||
// id, accounts and saved reads) or Remove from the list (no files touched). Shown in the app view and the folder list.
|
||||
import { useState } from 'react';
|
||||
import { api, errorText, type Project } from '../api';
|
||||
import { t } from '../i18n';
|
||||
import { useNav } from '../nav';
|
||||
import { shortPath } from '../paths';
|
||||
import { useData } from '../store';
|
||||
import { Icon } from './icons';
|
||||
import { Notice } from './kit';
|
||||
|
||||
export function useFolderActions(p: Project) {
|
||||
const d = useData();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const locate = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
const found = await api.locateProject(p.id);
|
||||
if (found) { await d.reload(); d.toast({ kind: 'ok', title: t('folder.located', { name: found.name }) }); }
|
||||
} catch (e) { d.toast({ kind: 'bad', title: t('folder.locateFailed'), detail: errorText(e) }); } finally { setBusy(false); }
|
||||
};
|
||||
const remove = async (after?: () => void) => {
|
||||
setBusy(true);
|
||||
try { await api.removeProject(p.id); await d.reload(); d.toast({ kind: 'ok', title: t('folder.removed', { name: p.name }) }); after?.(); }
|
||||
catch (e) { d.toast({ kind: 'bad', title: t('toast.saveFailed'), detail: errorText(e) }); } finally { setBusy(false); }
|
||||
};
|
||||
return { busy, locate, remove };
|
||||
}
|
||||
|
||||
export function FolderMissing({ project }: { project: Project }) {
|
||||
const d = useData();
|
||||
const nav = useNav();
|
||||
const { busy, locate, remove } = useFolderActions(project);
|
||||
return (
|
||||
<Notice tone="warn" icon="folder" action={<div className="actions">
|
||||
<button className="btn btn-sm btn-primary" onClick={locate} disabled={busy} title={t('folder.locateHint')}><Icon name="search" />{t('folder.locate')}</button>
|
||||
<button className="btn btn-sm" onClick={() => remove(() => nav.go({ screen: 'portfolio' }))} disabled={busy}><Icon name="trash" />{t('folder.remove')}</button>
|
||||
</div>}>
|
||||
<b>{t('folder.missing')}</b> {t('folder.missingText', { path: shortPath(project.path, d.info?.home) })}
|
||||
</Notice>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue