digidem / digidem/comapeo-core-react

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

Open
#203 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1
Forks
1
Avg merge
5m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in contexts/MapServer.ts and trace uploadFile into useImportCustomMapFile. Check how the expo-file-system File.upload path and the api.put path receive options, then determine how cancellation should be distinguished from genuine failures. Done means signal and onProgress reach both upload paths and callers can observe progress and abort without reporting a normal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
api, mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.