Skip to content

Commit 3cb99ce

Browse files
fix(mobile): attaching larger images no longer crashes with a BigInt error (#34087)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 1a2a4a5 commit 3cb99ce

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎apps/mobile/src/lib/attachmentUpload.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,27 @@ describe("prepareTurnAttachments", () => {
321321

322322
// regression: #9713 read file-backed image drafts before enabling them
323323
it("uploads a file-backed image from its owned copy without staging base64", async () => {
324+
mocks.upload.mockImplementation(
325+
async (
326+
_uri: string,
327+
_url: string,
328+
options: { onProgress?: (event: { bytesSent: unknown; totalBytes: unknown }) => void },
329+
) => {
330+
// expo-modules-jsi delivers native Int64 progress counts as BigInt.
331+
options.onProgress?.({ bytesSent: BigInt(1), totalBytes: BigInt(4) });
332+
return { status: 204, body: "", headers: {} };
333+
},
334+
);
335+
const progress: Array<number> = [];
324336
const prepared = await prepareTurnAttachments({
325337
environmentId,
326338
attachments: [fileBackedImage],
327339
supportsImageUploads: true,
340+
onUploadProgress: (_, value) => progress.push(value),
328341
});
329342

343+
expect(progress).toEqual([0.25]);
344+
330345
expect(mocks.upload).toHaveBeenCalledWith(
331346
fileBackedImage.fileUri,
332347
"https://environment.example/api/attachments/upload/signed",

‎apps/mobile/src/lib/attachmentUpload.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,10 @@ async function uploadFileBytes(
232232
signal,
233233
...(onProgress
234234
? {
235+
// Native events carry Int64 counts, which expo-modules-jsi delivers as BigInt despite the `number` type.
235236
onProgress: ({ bytesSent, totalBytes }) => {
236-
if (totalBytes > 0) onProgress(bytesSent / totalBytes);
237+
const total = Number(totalBytes);
238+
if (total > 0) onProgress(Number(bytesSent) / total);
237239
},
238240
}
239241
: {}),

0 commit comments

Comments
 (0)