feat: forward signal and onProgress to file.upload() so map imports can be cancelled

Aperta
#203 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
react, typescript
Ambito
api, mobile-dev

Direzione di ricerca

Inizia da contexts/MapServer.ts e segui uploadFile fino a useImportCustomMapFile. Verifica come il percorso File.upload di expo-file-system e il percorso api.put ricevono le opzioni, quindi determina come distinguere l'annullamento dai fallimenti effettivi. Il lavoro è completato quando signal e onProgress raggiungono entrambi i percorsi di upload e i chiamanti possono osservare l'avanzamento e interrompere l'operazione senza segnalare un errore normale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

uploadFile in contexts/MapServer.ts forwards only httpMethod, headers and sessionType to file.upload():

const result = await file.upload(url, {
  httpMethod: 'PUT',
  headers: options.headers,
  sessionType: 'foreground',
})

expo-file-system's UploadOptions also accepts signal (an AbortSignal) and onProgress, and neither is plumbed through uploadFile or useImportCustomMapFile. Compounding it, File.upload() is return new UploadTask(this, url, options).uploadAsync() — the UploadTask is constructed and immediately discarded, so no handle escapes either.

The practical consequence is that an in-flight map import cannot be cancelled from JS at all, and its progress cannot be observed. Unmounting the screen, navigating away, or reloading the JS runtime all leave the upload running.

Why this matters beyond ergonomics

An abandoned upload doesn't just waste bandwidth — it blocks every subsequent import. @comapeo/map-server serialises PUT /maps/:mapId on a per-mapId mutex and awaits request.body.pipeTo(...) inside the lock with no timeout (digidem/comapeo-map-server#64), so a still-running or stalled upload makes later attempts queue with no response until the client's own timeout fires.

In CoMapeo mobile that client is expo-file-system's uploader, whose OkHttp timeout is a fixed, non-configurable 60 s. A real Sentry event (COMAPEO-2MJ, Pixel 9, dev build) shows the shape:

17:51:52  touch "Choose File"     <- attempt 1 starts
17:56:13  Navigation to Map       <- user gives up after 4m21s and walks away;
                                     attempt 1 keeps uploading, nothing cancels it
17:56:17  touch "Choose File"     <- attempt 2, 4 seconds later
17:58:18  ERROR: Unable to upload a file: timeout

Attempt 1 never errored — it was still holding the mutex. Attempt 2 queued behind it and timed out. From the user's side this reads as "map import is broken", and it reproduces for any file size, which is what makes it confusing to diagnose.

Being able to abort on unmount would have released the lock when the user navigated away, and onProgress would have shown whether any bytes moved at all — the single most useful datum when one of these fails.

Proposed change

Accept signal and onProgress in uploadFile's options and forward them:

const result = await file.upload(url, {
  httpMethod: 'PUT',
  headers: options.headers,
  sessionType: 'foreground',
  signal: options.signal,
  onProgress: options.onProgress,
})

and surface them on useImportCustomMapFile so callers can pass them per-mutation, e.g. mutate({ file, signal, onProgress }). An aborted upload should reject in a way callers can distinguish from a genuine failure, so it isn't reported as an error.

The non-isExpoFileWithUpload branch (api.put(path, { body: file, headers })) can take signal directly too, since fetch already accepts one — worth keeping the two paths consistent.

Happy to open a PR if this looks right.

Lingua principale
TypeScript
Stelle
1
Fork
1
Merge medio
21m
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di digidem/comapeo-core-react

Tutte le issue di digidem/comapeo-core-react

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.