fix: send ArrayBuffer request bodies safely - #139
Closed
PradyumnaShome wants to merge 1 commit into
Closed
Conversation
|
@maxvaljan is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
PradyumnaShome
marked this pull request as ready for review
July 11, 2026 06:41
Collaborator
|
Thanks for the PR . But this isnt the best way to do it . We should Ideally use Nitro Array buffers and something that works with prefetching too |
Collaborator
|
Fixed in #140 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArrayBuffer, without a base64 round trip, in both normal JS and worklet request construction.Data/ByteArraypayloads on iOS and Android.ArrayBuffer,Uint8Arraysubviews, empty bodies, non-ASCII bytes, and unchanged string behavior.Why
bodyBytesis currently typed as a string placeholder, and the request path does not upload the actual binary payload. A base64 bridge can restore correctness temporarily, but it adds encoding/decoding work and memory overhead. This PR carries the bytes as anArrayBufferinstead.Credit and relationship to existing work
Builds on and credits #112. The original commit remains authored by its contributor, and this draft intentionally preserves that approach rather than presenting it as unrelated work.
This is a separate PR because it rebases the change onto current
mainand adds the iOS lifetime fix described below. It is not intended as silent competition with #112; maintainers are welcome to choose the preferred PR or merge the safety work into the original approach.#138 is a temporary correctness/base64 fallback. The two PRs are alternatives/stages, not changes that should both remain in the final implementation long-term.
iOS ArrayBuffer lifetime
Local native validation exposed a crash with the runtime diagnostic:
The
JSArrayBufferpassed into a Hybrid method is borrowed and must not survive the synchronous JS call boundary. CallingArrayBufferHolder.toData(copyIfNeeded:)later from a SwiftTaskor detached work accesses it from the wrong thread.request,requestSync, andprefetchnow synchronously materialize the body as nativeDatabefore creating anyTask. The request passed across the async boundary is rebuilt without the borrowedArrayBuffer, and only native-safe values plus the copiedDataare captured. Android similarly copies into aByteArraybefore the Cronet request starts.Compatibility and limitations
Data/ByteArraycopies; it is intentionally safe, not zero-copy.ArrayBuffer, so apps must perform a native rebuild after upgrading. This should be called out in release notes; callers using the old placeholder string form must migrate.prefetch()supports binary bodies with the same synchronous lifetime copy. Persisted app-start prefetch configuration does not serialize a borrowedArrayBuffer; legacy stringbodyBytesentries are no longer forwarded as binary data.Validation
bun installbun run nitrogenbun --cwd packages/react-native-nitro-fetch test --runInBand— 15 passed, 2 existing todosbun run typechecklintandtypeshooksA clean native app rebuild and benchmark rerun are still pending. The iOS lifetime fix is based on the local native crash report above; no native benchmark numbers are claimed here.