Skip to content

feat(realtime): allow wait for pg changes - #2630

Merged
mandarini merged 1 commit into
masterfrom
feat/allow-wait-on-pg-changes-real-893
Aug 27, 2026
Merged

mandarini merged 1 commit into
masterfrom
feat/allow-wait-on-pg-changes-real-893

Conversation

@filipecabaco

Copy link
Copy Markdown
Member

🔍 Description

Adds a wait: true option so subscribe() doesn't report SUBSCRIBED until the server confirms the postgres_changes subscription is actually active ‚fixing a race where changes could be missed if the channel joined before replication was streaming.

config: {
  postgres_changes_options: {
    wait?: boolean     // wait for server confirmation before SUBSCRIBED
    timeout?: number   // ms to wait, default 15000
  }
}

If confirmation fails, you get CHANNEL_ERROR with the server's reason instead of a false SUBSCRIBED.

@filipecabaco
filipecabaco requested review from a team as code owners August 27, 2026 10:24
@github-actions github-actions Bot added the realtime-js Related to the realtime-js library. label Aug 27, 2026
@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: af9c7ff9-2a4d-4503-8078-5d20045255ff

📥 Commits

Reviewing files that changed from the base of the PR and between 8e1fe78 and b051766.

📒 Files selected for processing (3)
  • packages/core/realtime-js/src/RealtimeChannel.ts
  • packages/core/realtime-js/src/lib/constants.ts
  • packages/core/realtime-js/test/RealtimeChannel.postgres.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added configurable PostgreSQL change subscription behavior.
    • Channels can now wait for server confirmation before reporting a successful subscription.
    • Added configurable wait timeouts, with sensible defaults and support for custom subscription timeouts.
  • Bug Fixes

    • Improved subscription timeout handling when PostgreSQL change confirmation is pending.

Walkthrough

The channel now accepts postgres_changes_options with optional wait and timeout values. Configured options are included in the join payload. When waiting is enabled for PostgreSQL bindings, the join timeout uses the configured or default wait timeout plus an error grace period. Tests cover payloads, timeout selection, server responses, and subscription callback statuses.

Sequence Diagram(s)

sequenceDiagram
  participant RealtimeChannel
  participant RealtimeServer
  participant SubscribeCallback
  RealtimeChannel->>RealtimeServer: Join with postgres_changes_options
  RealtimeServer-->>RealtimeChannel: Confirm or reject PostgreSQL subscription
  RealtimeChannel-->>SubscribeCallback: Report SUBSCRIBED, CHANNEL_ERROR, or TIMED_OUT
Loading

Merge Risk: 🔵 Low · up to b0517

The opt-in wait mode may still report SUBSCRIBED before PostgreSQL replication is confirmed if the server returns a successful response without confirmation metadata, which could cause applications to miss changes. The PR is mergeable with explicit owner awareness or follow-up to enforce the server contract or fail closed.

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

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

@supabase/functions-js

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

@supabase/postgrest-js

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

@supabase/realtime-js

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

@supabase/storage-js

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

@supabase/supabase-js

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

commit: b051766

@coveralls

coveralls commented Aug 27, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 81.676% (+0.02%) from 81.655% — feat/allow-wait-on-pg-changes-real-893 into master

@mandarini
mandarini merged commit 4c1d78e into master Aug 27, 2026
31 checks passed
@mandarini
mandarini deleted the feat/allow-wait-on-pg-changes-real-893 branch August 27, 2026 12:33
mandarini pushed a commit to supabase/ssr that referenced this pull request Sep 2, 2026
This PR updates `@supabase/supabase-js` to v2.114.0.

**Source**: supabase-js-stable-release

---

## Release Notes

## v2.114.0

## 2.114.0 (2026-09-02)

### 🚀 Features

- **storage:** object versioning updates
([#2644](supabase/supabase-js#2644))

### 🩹 Fixes

- **auth:** unenroll the unverified factor after a failed registration
([#2641](supabase/supabase-js#2641))
- **deps:** override browserslist to patch high-severity advisories
([#2652](supabase/supabase-js#2652))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
- Miodrag Obradovic @Kjubikstronk
- Tyler Hillery
## v2.113.0

## 2.113.0 (2026-09-02)

### 🚀 Features

- **realtime:** allow wait for pg changes
([#2630](supabase/supabase-js#2630))

### ❤️ Thank You

- Filipe Cabaço @filipecabaco

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
grdsdev added a commit to supabase/sdk that referenced this pull request Nov 26, 2026
## Summary
- Registers `realtime.subscriptions.postgres_changes_wait` — the
wait-for-server-confirmation option on `postgres_changes` subscriptions
(`postgres_changes_options.wait` / `.timeout`), added to supabase-js in
[supabase-js#2630](supabase/supabase-js#2630).
- Adds a spec at `specs/realtime/subscriptions/postgres_changes_wait.md`
describing the behavior, prerequisites, and error/timeout conditions in
SDK-neutral terms.

## Test plan
- `npm run validate` — OK, capability matrix is valid
- `npm test` — 195 passed
- `npm run typecheck` — clean

Refs SDK-1650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

realtime-js Related to the realtime-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants