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

+16 -5
View File
@@ -1,11 +1,22 @@
import type { useT } from '@/i18n/useT'
import { isUnsaved, useReportStore } from '@/state/reportStore'
import { coreStopped } from './runtime'
/** The stopped text: the unsaved variant when the tab's copy of the report is stale. */
export function stoppedMessageKey(unsaved: boolean): string {
return unsaved ? 'core.stopped_unsaved' : 'core.stopped'
}
/**
* The alert after a core action failed: "try again" while a retry can work; once the engine
* stopped after its three recoveries, the clear final state (reload the page, the report is
* kept in the tab) instead of a retry that cannot succeed (owner decision 2026-10-15).
* The alert after a core action failed: the fallback ("try again") while a retry can work;
* once the engine stopped after its three recoveries, the clear final state instead of a
* retry that cannot succeed (owner decision 2026-10-15). Callers with their own fallback
* key pass it; this file is the only place that names these keys in a `t()` call.
*/
export function coreFailureMessage(t: ReturnType<typeof useT>): string {
return t(coreStopped() ? 'core.stopped' : 'core.action_failed')
export function coreFailureMessage(
t: ReturnType<typeof useT>,
fallbackKey = 'core.action_failed',
): string {
if (!coreStopped()) return t(fallbackKey)
return t(stoppedMessageKey(isUnsaved(useReportStore.getState())))
}
+11
View File
@@ -1,3 +1,4 @@
import { useSyncExternalStore } from 'react'
import glueUrl from '@faunosteo/core-wasm/pkg/faunosteo_wasm.js?url'
import wasmUrl from '@faunosteo/core-wasm/pkg/faunosteo_wasm_bg.wasm?url'
import {
@@ -39,6 +40,16 @@ export function coreStopped(): boolean {
return runtime?.stopped ?? false
}
/** Subscribes to the runtime's status changes (stable identity for `useSyncExternalStore`). */
export function subscribeCore(listener: () => void): () => void {
return coreRuntime().subscribe(listener)
}
/** Whether the engine stopped for good on this page; re-renders when it does. */
export function useCoreStopped(): boolean {
return useSyncExternalStore(subscribeCore, coreStopped)
}
/** The page's runtime, created on first use. */
export function coreRuntime(): CoreRuntime {
runtime ??= new CoreRuntime(browserSource)
+1 -1
View File
@@ -14,7 +14,7 @@ import type {
/**
* The sheet-bound rules of the editor, run by the core on the session's sheet (R2): one
* call per user action or load, never in a render. Each returns the core's outcome; the
* caller stops on `ok: false` (nothing is written, the action shows `core.action_failed`).
* caller stops on `ok: false` (nothing is written, the action shows `coreFailureMessage`).
*/
export interface FindingToggle {