From 43d44e1a97287f01df7fd307865a96db7cea22fd Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Mon, 9 Nov 2026 08:30:20 +0000 Subject: [PATCH] fix(mobile): retry a failed draft read after a pause and keep New issue text typed during a create --- mobile/src/drafts/durable-draft-rows.ts | 15 ++++++++------- .../use-mobile-tasks-task-create-actions.tsx | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/mobile/src/drafts/durable-draft-rows.ts b/mobile/src/drafts/durable-draft-rows.ts index 5e65f00c67c..a9e891ac3c6 100644 --- a/mobile/src/drafts/durable-draft-rows.ts +++ b/mobile/src/drafts/durable-draft-rows.ts @@ -40,8 +40,8 @@ type Row = { // Every read and write of the row runs in order, the load first. chain: Promise state: 'pending' | 'loaded' - // A row whose read fails twice stays in memory for the page, so every hook and save doesn't read again. - failedReads: number + // After a failed read, no hook or save reads again until then; the text stays in memory meanwhile. + retryReadAt: number // What the backend holds; undefined after a failed write, so the next save cannot match it. written: string | undefined timer: ReturnType | null @@ -50,7 +50,8 @@ type Row = { const rows = new Map() -const MAX_FAILED_READS = 2 +// One retry per row at most this often, however many hooks open it or saves land. +const READ_RETRY_MS = 10_000 /** A value past the store's cap is refused and would leave an older value behind, so owners keep none instead. */ export function fitsDeviceStore(value: unknown): boolean { @@ -131,14 +132,14 @@ function enqueue(row: Row, step: () => Promise): Promise { } async function load(row: Row): Promise { - if (row.state !== 'pending' || row.failedReads >= MAX_FAILED_READS) { + if (row.state !== 'pending' || Date.now() < row.retryReadAt) { return } row.backend ??= row.owner.backend() const read = await row.backend.read() if (!read.ok) { - // A dropped or refused read is retried once, backend re-picked; until then the text stays in memory. - row.failedReads += 1 + // A dropped or refused read is retried later, backend re-picked; until then the text stays in memory. + row.retryReadAt = Date.now() + READ_RETRY_MS row.backend = null return } @@ -202,7 +203,7 @@ export function durableDraftRow(key: string, owner: DurableDraftRowOwner): Durab backend: null, chain: Promise.resolve(), state: 'pending', - failedReads: 0, + retryReadAt: 0, written: undefined, timer: null, handle: { diff --git a/mobile/src/tasks/use-mobile-tasks-task-create-actions.tsx b/mobile/src/tasks/use-mobile-tasks-task-create-actions.tsx index 59e08b80ce2..d794ab4f4f1 100644 --- a/mobile/src/tasks/use-mobile-tasks-task-create-actions.tsx +++ b/mobile/src/tasks/use-mobile-tasks-task-create-actions.tsx @@ -141,8 +141,9 @@ export function useMobileTasksTaskCreateActions(model: LinearItemActionsModel) { ) } setShowCreateTask(false) - setCreateTitle('') - setCreateBody('') + // Text typed while the create ran, here or in a reopened sheet, is not what it sent. + setCreateTitle((current) => (current === createTitle ? '' : current)) + setCreateBody((current) => (current === createBody ? '' : current)) await loadTasks({ silent: true }) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to create task')