fix(app): card retry keeps focus and voice when no retry is left

A retry ending on a failure with no retry (network to integrity, engine
stopped for good) keeps the polite region and moves focus to Consulter.
Busy look on Réessayer, error tone once the engine stopped, one attempt
for two calls in one tick; tests for the stopped engine, two core cards
and no blob URL after unmount.
This commit is contained in:
bchanot committed 2026-11-17 00:59:30 +01:00
1 parent 4a7919c763
commit b378cf066f
4 files changed
+97 -15

No files matched your search

+7 -2
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { listSheetVersions, type FaunosteoClient } from '@faunosteo/supabase'
import { coreRuntime } from '@/core/runtime'
import { getSupabaseClient } from '@/lib/supabase'
@@ -64,6 +64,9 @@ async function loadCard(
export function useCardDetails(entry: CatalogEntry): { state: CardState; retry: () => void } {
const [state, setState] = useState<CardState>({ status: 'loading' })
const [attempt, setAttempt] = useState(0)
// Set by the first call, cleared when its attempt settles: two calls in one
// tick start one attempt.
const running = useRef(false)
useEffect(() => {
let live = true
@@ -72,6 +75,7 @@ export function useCardDetails(entry: CatalogEntry): { state: CardState; retry:
if (!client) return
void loadCard(client, entry.sheet_id, entry.version_id).then((load) => {
if (!live) return
running.current = false
if (!load.ok) {
setState({ status: 'failed', failure: load.failure, retrying: false, attempt })
return
@@ -90,7 +94,8 @@ export function useCardDetails(entry: CatalogEntry): { state: CardState; retry:
const failed = state.status === 'failed' && !state.retrying ? state : null
// Ignored while an attempt runs; the core may need a restart before the card loads again.
const retry = useCallback(() => {
if (!failed) return
if (!failed || running.current) return
running.current = true
setState({ ...failed, retrying: true })
const restart =
failed.failure === 'core_unavailable' ? coreRuntime().retry() : Promise.resolve(true)