fix(editor): honest stopped state when the draft is unsaved; no dead retry

0279953 chose the stopped message from CoreRuntime.stopped alone: it
promised the report was kept even when the tab's storage refused the
draft (export, the banner's advice, needs the core), four surfaces still
offered a retry that could not work, and a failed recovery below the cap
was a dead end since nothing called retry().

The runtime restarts a failed recovery on the next call (compiled module
reused, cap still counts traps) and notifies status listeners. One
CoreStoppedNotice on the editor, Home, New report and the full-page
notice: reload when saved, else core.stopped_unsaved with a core-free
copy download (also on the storage-full banner) and a beforeunload
guard. Export, import and new report say the stopped message; a core
failure reading an unread draft is FAILED, not held. ESLint census of
the failure keys; core.stopped says "plusieurs erreurs".
This commit is contained in:
bchanot committed 2026-10-16 18:26:10 +02:00
1 parent 0279953e9e
commit 6371523f8c
24 files changed
+839 -83

No files matched your search

+28 -5
View File
@@ -14,11 +14,13 @@ import EditInfosDialog, {
type Identity,
} from '@/components/report/EditInfosDialog'
import DisclaimerDialog from '@/components/report/DisclaimerDialog'
import CoreStoppedNotice, { CopyReportButton } from '@/components/report/CoreStoppedNotice'
import CoreUnavailable from '@/components/report/CoreUnavailable'
import HeldSessionPanel from '@/components/report/HeldSessionPanel'
import Notice from '@/components/ui/Notice'
import Button from '@/components/ui/Button'
import {
isUnsaved,
useReportStore,
type ActionResult,
type HeldText,
@@ -37,6 +39,7 @@ import type { RebaseOutcome } from '@faunosteo/core-wasm/types'
import { useT } from '@/i18n/useT'
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
import { coreFailureMessage } from '@/core/failure'
import { useCoreStopped } from '@/core/runtime'
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
@@ -72,6 +75,8 @@ export default function EditorRoute() {
const { report, activeObservationIndex: activeIndex } = store
// Without a report yet (draft restore), the default species' sheet carries the migration map.
const sheet = useSheet(report?.animal.speciesId ?? DEFAULT_SPECIES_ID)
const stopped = useCoreStopped()
const unsaved = isUnsaved(store)
const [detailViewId, setDetailViewId] = useState<string | null>(null)
const [vertebraTarget, setVertebraTarget] = useState<VertebraTarget | null>(
@@ -132,6 +137,17 @@ export default function EditorRoute() {
navigate('/')
}, [report, sheet, store, navigate, t, restoreAttempt])
// The report lives only in this tab's memory: the browser asks before a reload or a close.
useEffect(() => {
if (!unsaved) return
const guard = (event: BeforeUnloadEvent) => {
event.preventDefault()
event.returnValue = ''
}
window.addEventListener('beforeunload', guard)
return () => window.removeEventListener('beforeunload', guard)
}, [unsaved])
const retryRestore = useCallback(() => setRestoreAttempt((n) => n + 1), [])
useEffect(() => {
@@ -248,7 +264,7 @@ export default function EditorRoute() {
}
} catch (err) {
console.error('PDF export failed', err)
window.alert(t('editor.export_failed'))
window.alert(coreFailureMessage(t, 'editor.export_failed'))
} finally {
setExporting(false)
}
@@ -300,10 +316,17 @@ export default function EditorRoute() {
})
}
/>
{store.saveFailed && (
<Notice tone="error" className="mx-4 sm:mx-6 mt-4">
{t('editor.save_failed')}
</Notice>
{stopped ? (
<CoreStoppedNotice className="mx-4 sm:mx-6 mt-4" />
) : (
store.saveFailed && (
<Notice tone="error" className="mx-4 sm:mx-6 mt-4">
<p>{t('editor.save_failed')}</p>
<div className="mt-2">
<CopyReportButton />
</div>
</Notice>
)
)}
<div className="flex-1 grid grid-cols-1 lg:grid-cols-[2fr_3fr] gap-4 sm:gap-6 p-4 sm:p-6">
<section className="border border-[var(--color-border)] rounded-2xl bg-[var(--color-surface)] overflow-hidden max-h-[55vh] lg:max-h-none flex flex-col">
+6 -1
View File
@@ -6,6 +6,7 @@ import type {
} from '@faunosteo/core-wasm/types'
import AppHeader from '@/components/brand/AppHeader'
import HomeSpaceLink from '@/components/brand/HomeSpaceLink'
import { CoreStoppedBanner } from '@/components/report/CoreStoppedNotice'
import Button from '@/components/ui/Button'
import Card from '@/components/ui/Card'
import {
@@ -18,6 +19,7 @@ import { useReportStore } from '@/state/reportStore'
import { loadSheetIndex, useSheetAvailability } from '@/sheets/useSheet'
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
import { useT } from '@/i18n/useT'
import { coreFailureMessage } from '@/core/failure'
type Translate = ReturnType<typeof useT>
@@ -106,7 +108,7 @@ function importErrorMessage(err: unknown, t: Translate): string {
case 'lone_surrogate':
return t('home.import.error_lone_surrogate')
case 'core_unavailable':
return t('home.import.error_core_unavailable')
return coreFailureMessage(t, 'home.import.error_core_unavailable')
}
}
@@ -135,6 +137,8 @@ export default function HomeRoute() {
)
// A tab text that could not be set aside would be overwritten: resolve it first.
if (!opened.ok) {
// A core failure reading the tab's draft is an engine error, not a held text.
if (opened.reason !== 'held') throw new ImportError('core_unavailable')
window.alert(t('session.held_blocked'))
navigate('/editor')
return
@@ -166,6 +170,7 @@ export default function HomeRoute() {
<AppHeader>
<HomeSpaceLink />
</AppHeader>
<CoreStoppedBanner className="mx-4 sm:mx-6 mt-4" />
<section className="flex-1 grid place-items-center px-4 sm:px-6">
<div className="grid gap-4 md:grid-cols-2 max-w-3xl w-full">
{noSheet && (
+3 -1
View File
@@ -4,6 +4,7 @@ import type { Animal, Owner, Practitioner } from '@faunosteo/core-wasm/types'
import PractitionerForm from '@/components/report/PractitionerForm'
import AnimalForm from '@/components/report/AnimalForm'
import AppHeader from '@/components/brand/AppHeader'
import { CoreStoppedBanner } from '@/components/report/CoreStoppedNotice'
import Button from '@/components/ui/Button'
import Input from '@/components/ui/Input'
import Label from '@/components/ui/Label'
@@ -52,7 +53,7 @@ export default function NewReportRoute() {
// The loaded sheet lets the store read a draft this page never opened before replacing it.
const index = await loadSheetIndex(DEFAULT_SPECIES_ID)
if (!index) {
window.alert(t('sheet.core_unavailable'))
window.alert(coreFailureMessage(t, 'sheet.core_unavailable'))
return
}
const created = initReport(
@@ -79,6 +80,7 @@ export default function NewReportRoute() {
<main className="min-h-screen">
<AppHeader />
<div className="max-w-3xl mx-auto px-4 sm:px-6 py-6 sm:py-8 space-y-6 sm:space-y-8">
<CoreStoppedBanner />
<h1 className="font-serif text-2xl sm:text-3xl">
{t('new_report.title')}
</h1>