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:
1 parent
0279953e9e
commit
6371523f8c
24 files changed
+839
-83
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { buildViewSvg, type ViewFailure, type ViewStates } from '@/anatomy/drawing'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { coreRuntime, useCoreStopped } from '@/core/runtime'
|
||||
import { stoppedMessageKey } from '@/core/failure'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { isUnsaved, useReportStore } from '@/state/reportStore'
|
||||
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
@@ -17,7 +20,7 @@ export interface AnatomyCanvasProps {
|
||||
|
||||
const ANNOTATED = '[data-anno-id]'
|
||||
|
||||
/** Only an engine that can still recover offers a retry. */
|
||||
/** `engine_stopped` is replaced at render by the stopped text that fits the save state. */
|
||||
const FAILURE_MESSAGE: Record<ViewFailure, string> = {
|
||||
engine: 'sheet.core_unavailable',
|
||||
engine_stopped: 'core.stopped',
|
||||
@@ -34,7 +37,8 @@ function annotatedTarget(event: Event): Element | null {
|
||||
* the core (R3), rebuilt when the view changes and restyled in place when the
|
||||
* selection changes (the restyle runs right after every build). Clicks are
|
||||
* delegated on `data-anno-id`. When the engine cannot run, the canvas shows the
|
||||
* degraded notice with a retry; when the view itself cannot be drawn (a drawing
|
||||
* degraded notice with a retry (none once the engine stopped for good: the page's stopped
|
||||
* notice holds the buttons); when the view itself cannot be drawn (a drawing
|
||||
* refused or impossible to compose), a notice without retry: nothing would change.
|
||||
*/
|
||||
export default function AnatomyCanvas({
|
||||
@@ -52,6 +56,17 @@ export default function AnatomyCanvas({
|
||||
// Each retry builds again; a failed build leaves the canvas empty behind the notice.
|
||||
const [attempt, setAttempt] = useState(0)
|
||||
const [failure, setFailure] = useState<ViewFailure | null>(null)
|
||||
// Derived at render: an engine failure shown while the engine stops becomes the stopped text.
|
||||
const stopped = useCoreStopped()
|
||||
const unsaved = useReportStore(isUnsaved)
|
||||
const engineStopped = failure === 'engine_stopped' || (failure === 'engine' && stopped)
|
||||
|
||||
// A failed recovery below the cap needs the runtime restarted before the view is built again.
|
||||
const retryEngine = useCallback(() => {
|
||||
void coreRuntime()
|
||||
.retry()
|
||||
.finally(() => setAttempt((n) => n + 1))
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const host = svgRef.current
|
||||
@@ -140,11 +155,11 @@ export default function AnatomyCanvas({
|
||||
{failure && (
|
||||
<div className="absolute inset-0 grid place-items-center p-4">
|
||||
<div className="space-y-3 max-w-sm">
|
||||
<Notice tone="error">{t(FAILURE_MESSAGE[failure])}</Notice>
|
||||
{failure === 'engine' && (
|
||||
<Button onClick={() => setAttempt((n) => n + 1)}>
|
||||
{t('sheet.core_retry')}
|
||||
</Button>
|
||||
<Notice tone="error">
|
||||
{t(engineStopped ? stoppedMessageKey(unsaved) : FAILURE_MESSAGE[failure])}
|
||||
</Notice>
|
||||
{failure === 'engine' && !engineStopped && (
|
||||
<Button onClick={retryEngine}>{t('sheet.core_retry')}</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user