Skip to content

fix(postgrest): pass request headers as plain object for RN/custom-fetch compatibility#2414

Merged
mandarini merged 3 commits into
masterfrom
fix/postgrest-headers-plain-object
Jun 4, 2026
Merged

fix(postgrest): pass request headers as plain object for RN/custom-fetch compatibility#2414
mandarini merged 3 commits into
masterfrom
fix/postgrest-headers-plain-object

Conversation

@mandarini
Copy link
Copy Markdown
Contributor

@mandarini mandarini commented Jun 1, 2026

Summary

Passes request headers to the user-supplied fetch as a plain object instead of a Headers instance. Picks up the intent of #2017 from @dev-hari-prasad with a minimal, focused change.

Why

React Native's XHR-based fetch polyfill (whatwg-fetch) silently drops headers — most notably Content-Type — when given a Headers instance. Without Content-Type: application/json, PostgREST cannot parse the JSON body, and a parameter-less rpc() call surfaces as a confusing PGRST202 ("Searched for the function with a single unnamed text parameter").

See:

Alignment with sibling packages

The sibling clients have always handled headers as plain objects internally and at the fetch call site:

  • auth-jssrc/lib/fetch.ts spreads { 'Content-Type': '...', ...options?.headers } into request params.
  • storage-jsBaseApiClient.headers: { [key: string]: string }.
  • functions-jsFunctionsClient.headers: Record<string, string>.

postgrest-js was the outlier: a previous refactor (postgrest-js#619, "chore: refactor in favor of Headers API") moved it to wrap headers in new Headers(...) at the fetch boundary, primarily to get ergonomic multi-value handling for the Prefer header.

This PR keeps that ergonomic win — the internal this.headers storage stays a Headers instance, so Prefer append-style construction continues to work as designed — and only flattens to a plain object at the moment of the _fetch() call. Wire-level behavior to PostgREST is unchanged on standard runtimes (native fetch normalizes either form); the change only affects what user-supplied fetch wrappers see.

Behavior note for custom fetch consumers

Headers handed to a user-supplied fetch are now a plain Record<string, string> with lowercase keys (per Headers.prototype.forEach semantics). Wrappers that previously did req.headers.get('Content-Type') should switch to req.headers['content-type'].

Tests

  • New: test/headers-serialization.test.ts — asserts the request handed to a custom fetch has content-type: application/json reachable by plain-object key access (i.e. what the RN polyfill would see).
  • Updated: test/fetch-errors.test.ts, test/retry.test.ts, test/basic.test.ts to reflect the plain-object shape on the wire.

Closes #1562.

@github-actions github-actions Bot added the postgrest-js Related to the postgrest-js library. label Jun 1, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 1, 2026

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2414

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2414

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2414

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2414

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2414

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2414

commit: eca699f

@mandarini mandarini self-assigned this Jun 1, 2026
@mandarini mandarini force-pushed the fix/postgrest-headers-plain-object branch from 36829dd to 83b4b87 Compare June 1, 2026 14:00
@mandarini mandarini force-pushed the fix/postgrest-headers-plain-object branch from 83b4b87 to eca699f Compare June 4, 2026 12:00
@mandarini mandarini marked this pull request as ready for review June 4, 2026 12:01
@mandarini mandarini requested review from a team as code owners June 4, 2026 12:01
@mandarini mandarini merged commit 2edb581 into master Jun 4, 2026
26 of 29 checks passed
@mandarini mandarini deleted the fix/postgrest-headers-plain-object branch June 4, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postgrest-js Related to the postgrest-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

supabase-js rpc() fails with PGRST202 for parameter-less functions in React Native

2 participants