fix(offline): a write the server keeps failing on no longer blocks every other write

A queued change the server answered with a 5xx was put back at the head
of the line and the whole flush stopped, every 30 seconds, forever: one
bad payload held every later change of every trip. Now only its own
trip waits, with gaps doubling from 30 s, and after eight failures it is
parked as failed. A DELETE answered 404 counts as done instead of
showing as a failed sync. Settings > Offline offers to try parked
changes again or discard them.
This commit is contained in:
Maurice
2026-10-07 16:30:07 +02:00
parent 3f9b751ee3
commit f092e7a95f
34 changed files with 331 additions and 6 deletions
@@ -44,6 +44,8 @@ const h = vi.hoisted(() => {
conflicts: vi.fn(),
resolveKeepMine: vi.fn(),
resolveKeepServer: vi.fn(),
retryFailed: vi.fn(),
discardFailed: vi.fn(),
clearTileCache: vi.fn(),
};
});
@@ -68,6 +70,8 @@ vi.mock('../../sync/mutationQueue', async (importOriginal) => {
conflicts: h.conflicts,
resolveKeepMine: h.resolveKeepMine,
resolveKeepServer: h.resolveKeepServer,
retryFailed: h.retryFailed,
discardFailed: h.discardFailed,
},
};
});
@@ -236,6 +240,21 @@ describe('OfflineTab', () => {
expect(within(stat('Conflicts')).getByText('1')).toBeInTheDocument();
});
it('FE-COMP-OFFLINETAB-030: failed changes offer to try them again or discard them', async () => {
h.failedCount.mockResolvedValue(2);
h.retryFailed.mockResolvedValue(undefined);
h.discardFailed.mockResolvedValue(undefined);
h.syncAll.mockResolvedValue([]);
const user = userEvent.setup();
render(<OfflineTab />);
await user.click(await screen.findByRole('button', { name: 'Try again' }));
expect(h.retryFailed).toHaveBeenCalledTimes(1);
await user.click(screen.getByRole('button', { name: 'Discard' }));
expect(h.discardFailed).toHaveBeenCalledTimes(1);
expect(screen.getByText(/never reached the server/)).toBeInTheDocument();
});
it('FE-COMP-OFFLINETAB-008: conflicts are named from the queued body, the server copy or the entity id', async () => {
h.conflicts.mockResolvedValue([
conflict({ id: 'a', body: { name: 'Louvre' } }),
+17 -1
View File
@@ -41,7 +41,7 @@ export default function OfflineTab(): React.ReactElement {
syncing, clearing, loading, preparing, progress, notice, prefs, canClear,
runPrepare, handleToggleForce, handleResync, handleClear,
handleToggleTiles, tripStorageState, handleToggleTrip, resolveConflict,
handleConflictStrategy,
handleConflictStrategy, retryFailed, discardFailed,
} = useOfflineSettings()
const [confirmClear, setConfirmClear] = useState(false)
@@ -226,6 +226,22 @@ export default function OfflineTab(): React.ReactElement {
{failedCount > 0 && <Stat label={t('settings.offline.stats.failed')} value={failedCount} danger />}
</div>
{failedCount > 0 && (
<div className="flex flex-wrap items-center justify-between gap-3">
<SettingsHint>{t('settings.offline.failed.hint')}</SettingsHint>
<div className="flex gap-2">
<button type="button" onClick={() => void retryFailed()} disabled={offline} className={SETTINGS_BUTTON} style={fs(12.5, 'body')}>
<RefreshCw size={14} />
{t('settings.offline.failed.retry')}
</button>
<button type="button" onClick={() => void discardFailed()} className={SETTINGS_BUTTON_DANGER} style={fs(12.5, 'body')}>
<Trash2 size={14} />
{t('settings.offline.failed.discard')}
</button>
</div>
</div>
)}
{loading ? (
<div className="flex items-center gap-2 text-content-faint" style={fs(12, 'body')}>
<RefreshCw size={13} className="animate-spin" />
@@ -256,6 +256,17 @@ export function useOfflineSettings() {
await load()
}, [load, tripStorageState])
const retryFailed = useCallback(async () => {
await mutationQueue.retryFailed()
await load()
}, [load])
const discardFailed = useCallback(async () => {
await mutationQueue.discardFailed()
if (!isEffectivelyOffline()) await tripSyncManager.syncAll().catch(() => null)
await load()
}, [load])
const resolveConflict = useCallback(async (id: string, keepMine: boolean) => {
if (keepMine) await mutationQueue.resolveKeepMine(id)
else await mutationQueue.resolveKeepServer(id)
@@ -277,6 +288,6 @@ export function useOfflineSettings() {
canClear: storedTripCount > 0 || pendingCount > 0,
load, runPrepare, handleToggleForce, handleResync, handleClear,
handleToggleTiles, tripStorageState, handleToggleTrip, resolveConflict,
handleConflictStrategy,
handleConflictStrategy, retryFailed, discardFailed,
}
}