Skip to content

refactor(realtime)!: clean up connection naming on RealtimeClient - #1404

Merged
spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-583-realtime-v3-renames
Aug 6, 2026
Merged

spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-583-realtime-v3-renames

Conversation

@spydon

@spydon spydon commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Cleans up the connection-related naming on RealtimeClient. Split out of #1397 so that PR could carry only the protocol 2.0.0 feature without breaking changes.

Spell out the conn abbreviation

Before After
RealtimeClient.conn connection
RealtimeClient.connState connectionState (see below)
RealtimeClient.onConnMessage onConnectionMessage

Private and local: _onConnOpen / _onConnClose / _onConnError became _onConnectionOpen / _onConnectionClose / _onConnectionError, and the localConn local in connect() became localConnection.

Also the shortenings the rename itself did not reach: the heartbeat timeout log message now reads "Attempting to re-establish connection", a channel_test description that said "via ws conn", and chanParams on the test stub's channel override (renamed to config, matching the RealtimeClient.channel signature it overrides).

Collapse the two socket-state accessors

Spelling out connState left it one word away from the existing String get connectionState, and both carried the same information. The stringly typed getter is gone and the typed field takes the name:

// before
SocketStates? connState;
String get connectionState => switch (connState) { ... };

// after
SocketState? connectionState;

For the string form use connectionState?.name; for the common case isConnected is unchanged.

Singularize the enum

SocketStates is now SocketState, matching Dart convention and the large majority of the 51 enums in the repository.

Consumers updated: supabase_flutter (supabase.dart, lifecycle_test.dart).

Breaking changes

  • RealtimeClient.conn → connection
  • RealtimeClient.onConnMessage → onConnectionMessage
  • RealtimeClient.connState → connectionState
  • RealtimeClient.connectionState changes type from String to SocketState?. This one is a silent change for anyone reading it as a string, so it is worth calling out in the release notes.
  • SocketStates → SocketState

Renames and one removal. No behaviour change.

Capability matrix

RealtimeClient.connection, RealtimeClient.onConnectionMessage, and SocketState are registered in sdk-compliance.yaml. RealtimeClient.connectionState keeps its name and its existing entry.

Notes

Tests

realtime_client 203 passing, supabase 135 passing, supabase_flutter 63 passing. dart analyze and dart format clean. The capability matrix symbol and schema checks were run locally against main and pass.

Summary by CodeRabbit

  • Breaking Changes

    • Renamed realtime connection APIs for clearer terminology, including SocketState, connection, connectionState, and onConnectionMessage.
    • Removed the previous string-based connection-state getter.
    • Connection status is now represented directly through typed socket states.
  • Bug Fixes

    • Disconnecting now reliably cancels pending reconnect attempts and clears the active connection.
  • Documentation

    • Updated SDK capability information to reflect the renamed realtime APIs.

spydon added a commit that referenced this pull request Jun 12, 2026
## What

Adds Realtime protocol **2.0.0** support to the Dart/Flutter SDK and
makes the protocol version selectable.

Closes
[SDK-583](https://linear.app/supabase/issue/SDK-583/realtime-add-support-to-protocol-format-200-flutter).

Protocol 2.0.0 changes the WebSocket frame format:
- **Text frames** use the positional JSON array `[join_ref, ref, topic,
event, payload]` instead of the 1.0.0 object layout, reducing JSON work
on the backend (lower latency).
- **Binary frames** allow raw binary payloads for broadcast user events.

## Changes

### Serializer (`serializer.dart`, new)
- Text encode/decode as the positional array `[join_ref, ref, topic,
event, payload]`.
- Binary encode for broadcast pushes (`userBroadcastPush`, kind `3`).
- Binary decode for incoming broadcasts (`userBroadcast`, kind `4`).
- JSON/binary encoding flag and `allowedMetadataKeys`.
- `decode` validates the text frame shape and throws a clear
`FormatException` on malformed input; `onConnMessage` logs and drops
such frames instead of crashing the connection.

### Selectable protocol version
- New `RealtimeProtocolVersion` enum (`v1` → `1.0.0`, `v2` → `2.0.0`);
each carries the `vsn` value sent as the connection parameter.
- `RealtimeClient` takes a `version` parameter, **defaulting to `v2`**.
`v2` uses the serializer; `v1` uses the legacy object-shaped JSON
frames.

### Codec override
- Optional `encode` / `decode` constructor arguments (and the
`RealtimeEncode` / `RealtimeDecode` typedefs) let consumers swap in a
custom serializer; they default to the codec for the selected `version`.
- Return-based signatures: `RealtimeEncode` = `Object
Function(Map<String, dynamic>)`, `RealtimeDecode` = `Map<String,
dynamic> Function(Object)` (synchronous — async/isolate codec is a
follow-up, see below).

### Binary broadcasts
Incoming binary broadcast frames are decoded into the same map shape as
JSON broadcasts. To send binary, provide a `Uint8List` (or any
`TypedData`) under the `payload` key:

\`\`\`dart
channel.sendBroadcastMessage(event: 'file', payload: {'payload':
myUint8List});
\`\`\`

Binary frames are delivered as `Uint8List` on every platform; the web
transport sets `binaryType` to arraybuffer explicitly.

### Misc
- Expanded a few abbreviated identifiers (`obj`/`msg`/`res`) in touched
code.

## Breaking changes

- **Default Realtime protocol is now `2.0.0`** (pass `version:
RealtimeProtocolVersion.v1` to keep the old behavior).
- `RealtimeEncode` / `RealtimeDecode` changed from callback-based to
return-based signatures.

## Related

- The breaking field/method renames (`conn` → `connection`, `connState`
→ `connectionStatus`, `onConnMessage` → `onConnectionMessage`) are split
into #1404, which stacks on this PR and will be retargeted to `v3` after
this merges.
- Follow-up: async codec path for isolate offloading — #1401.

## Tests

- `realtime_client`: 121 passing (new `serializer_test.dart`,
endpointURL `v1`, legacy encode, legacy decode + dispatch,
custom-`encode` override, malformed-frame, binary-broadcast receive).
- `supabase`: 83 passing.
- `supabase_flutter/test/lifecycle_test.dart`: analyze clean.
Base automatically changed from lukasklingsbo/sdk-583-realtime-protocol-200 to main June 12, 2026 15:13
@spydon spydon added the v3 label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The realtime client renames SocketStates to SocketState, conn to connection, connState to connectionState, and onConnMessage to onConnectionMessage. Lifecycle code, tests, and SDK compliance metadata now use the renamed APIs.

Changes

Realtime connection API rename

Layer / File(s) Summary
Client contract and lifecycle updates
packages/realtime_client/lib/...
The exported socket state enum and realtime client connection APIs use the new names. Lifecycle, callbacks, disconnect handling, message handling, and heartbeat handling use the renamed fields and enum values.
Realtime client test updates
packages/realtime_client/test/...
Socket, heartbeat, channel, and mocked-channel tests use the renamed APIs and parameter.
Flutter integration and compliance updates
packages/supabase_flutter/..., sdk-compliance.yaml
Flutter lifecycle logic and tests use the renamed connection APIs. SDK compliance symbols list the new API names.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested reviewers: grdsdev

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the connection-naming cleanup in RealtimeClient.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lukasklingsbo/sdk-583-realtime-v3-renames

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.

@spydon
spydon force-pushed the lukasklingsbo/sdk-583-realtime-v3-renames branch from c3ea0b8 to 40058c5 Compare August 5, 2026 13:43
spydon added 2 commits August 5, 2026 15:51
BREAKING CHANGE: RealtimeClient.conn -> connection, connState ->
connectionStatus, onConnMessage -> onConnectionMessage, and the private
_onConn* handlers -> _onConnection*.
Spell out the leftover `conn` shortenings the rename missed: the heartbeat
timeout log message, a test description, and the `chanParams` parameter on
the test stub's `channel` override (renamed to `config` to match the
`RealtimeClient.channel` signature it overrides).
@spydon
spydon force-pushed the lukasklingsbo/sdk-583-realtime-v3-renames branch from 40058c5 to e9713f8 Compare August 5, 2026 13:52
@spydon spydon changed the title refactor(realtime)!: rename conn family and onConnMessage refactor(realtime)!: spell out the conn abbreviation on RealtimeClient Aug 5, 2026
`RealtimeClient` exposed both a `String get connectionState` and a
`SocketStates? connState` holding the same information, and after spelling
out the abbreviation the two names sat one word apart. Drop the stringly
typed getter and let the typed field take the `connectionState` name, so
there is a single way to read socket state.

Also rename the enum to the singular `SocketState`, matching Dart
convention and the rest of the enums in the repository.

BREAKING CHANGE: `RealtimeClient.connectionState` is now `SocketState?`
instead of `String`; use `connectionState?.name` for the string form or
`isConnected` for the common case. The `SocketStates` enum is renamed to
`SocketState`.
@spydon spydon changed the title refactor(realtime)!: spell out the conn abbreviation on RealtimeClient refactor(realtime)!: clean up connection naming on RealtimeClient Aug 5, 2026
@spydon
spydon marked this pull request as ready for review August 5, 2026 14:18
@spydon
spydon requested a review from a team as a code owner August 5, 2026 14:18
@spydon
spydon merged commit 4344c34 into main Aug 6, 2026
47 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-583-realtime-v3-renames branch August 6, 2026 07:14
spydon added a commit that referenced this pull request Aug 6, 2026
…1654)

Closes #1652

## What

A Dart enum type names one value rather than the set, so its name should
be singular. Five enums were ports of `realtime-js` / `gotrue-js` names
instead:

| Before | After | Was reachable by consumers? |
| --- | --- | --- |
| `ChannelStates` | `ChannelState` | No (omitted from the `show` list) |
| `ChannelEvents` | `ChannelEvent` | No (omitted from the `show` list) |
| `RealtimeListenTypes` | `RealtimeListenType` | No (named in the `hide`
clause) |
| `PostgresTypes` | `PostgresType` | Yes |
| `AuthenticatorAssuranceLevels` | `AuthenticatorAssuranceLevel` | Yes |

The three unreachable ones are now annotated `@internal`, which is both
the accurate annotation and enough to keep them out of the capability
matrix scan.

Sweeping the rest of the monorepo's 51 enums turned up one more name
that did not read as a noun naming a single value: `LoadTableSnapshots`
(storage, Iceberg) is now `TableSnapshotScope`.

## Enum extensions folded in

Enums can declare methods and static methods directly, so every
extension that only existed to hang helpers off an enum is now part of
the enum:

- `ChannelEventsExtended` → `ChannelEvent.fromType` /
`ChannelEvent.eventName`
- `ToType` → `RealtimeListenType.toType`
- `PostgresChangeEventMethods` → `PostgresChangeEvent.fromString` /
`PostgresChangeEvent.toRealtimeEvent`
- `PresenceEventExtended` → `PresenceEvent.fromString`
- `AuthChangeEventExtended` → `AuthChangeEvent.fromString`
- `GenerateLinkTypeExtended` → `GenerateLinkType.fromString`

Those helpers decode wire values, so the folded members carry
`@internal`, matching the visibility the extensions already had through
the `hide` clauses. The now-unnecessary `hide` entries are dropped from
the gotrue and realtime_client exports.

`SupabaseEventTypesName` is deliberately left alone: its member is
`name()`, which would shadow `Enum.name` if declared on the enum, and
both it and its deprecated enum are due for removal anyway.

## Not changed

- `SocketStates`, because #1404 already renames it.
- `AMRMethod` / `AMREntry` violate Dart's "capitalize acronyms longer
than two letters like words" rule (`AmrMethod` / `AmrEntry`). Out of
scope here, worth a follow-up.
- `RequestMethodType` in gotrue is replaced by the shared `HttpMethod`
in #1645.
- `FactorStatus`, `RealtimeHeartbeatStatus` and
`RealtimeSubscribeStatus` end in `s` but are singular ("status").
- Enum *values* such as `GenerateLinkType.magiclink` and
`OtpType.magiclink` are not lowerCamelCase, but they are load-bearing:
the wire value is derived from the value name.

## Behaviour

None. No enum value changes: `ChannelEvent.eventName()` still produces
the same `phx_*` strings and `TableSnapshotScope` still sends `all` /
`refs`.

## Capability matrix

`PostgresType`, `AuthenticatorAssuranceLevel` and `TableSnapshotScope`
are registered under `realtime.subscriptions.postgres_changes`,
`auth.mfa.get_authenticator_assurance_level` and
`storage.analytics.iceberg_table` (replacing the stale
`LoadTableSnapshots` entries).

## Testing

- `dart analyze packages examples`: clean
- `realtime_client`, `supabase`, `supabase_flutter` suites: pass
- `gotrue` MFA, constants and types suites: pass (the rest of the
`gotrue` suite has pre-existing failures against my local stack on
`main` too)
- supabase/sdk `check-api-symbols`, `check-drift` and
`validate-compliance` run locally against this branch: all pass

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Breaking Changes**
- Renamed authentication assurance-level, realtime channel/event,
Postgres type, and table snapshot enums.
- Updated related method parameters and response fields to use the new
names.

- **Improvements**
  - Simplified enum parsing and conversion APIs.
  - Corrected public exports for supported types and utilities.
- Preserved existing authentication, MFA, realtime, storage, and
data-conversion behavior.

- **Tests**
- Updated coverage for enum parsing, serialization, realtime events, and
MFA flows.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
spydon added a commit that referenced this pull request Aug 6, 2026
Closes SDK-1425

## What

v3 is accumulating breaking changes across every package in the monorepo
(#1278), and there is nowhere a user can look to find out what they have
to change in their own code. The changelogs are per package,
auto-generated and one line per commit, so anyone upgrading has to read
seven of them and reconstruct the migration themselves.
`sdk-compliance.yaml` tracks capabilities, not migrations.

This adds a `MIGRATION.md` at the repository root, modelled on [Flame's
migration
guide](https://github.com/flame-engine/flame/blob/main/doc/flame/migration.md):

- One section per major version step, newest first: `## Migrating from
v2 to v3`.
- One `###` subsection per breaking change, titled after what changed.
- Each subsection says why the change was made and what you have to do,
with a `// Before` / `// After` Dart snippet.
- Changes that keep their name but change type or behaviour are called
out explicitly, since those do not surface as compile errors.

One file for the whole monorepo rather than one per package, because the
packages go major in lockstep, and it gives us a single link to hand to
users.

## Covered so far

The two breaking commits that have landed on `main`:

- `RealtimeClient.connectionState` changing from `String` to
`SocketState?` (#1404). This is the silent one: the name is unchanged,
so anyone comparing it against `'open'` gets no compile error.
- The `conn` abbreviations spelled out: `conn` → `connection`,
`connState` → `connectionState`, `onConnMessage` → `onConnectionMessage`
(#1404).
- The four consumer-reachable enum renames (#1654): `SocketStates` →
`SocketState`, `PostgresTypes` → `PostgresType`,
`AuthenticatorAssuranceLevels` → `AuthenticatorAssuranceLevel`,
`LoadTableSnapshots` → `TableSnapshotScope`.

Left out on purpose: the three enums that were never exported
(`ChannelStates`, `ChannelEvents`, `RealtimeListenTypes`) and the enum
extensions folded in by #1654, since all of them are `@internal` and
cannot break a consumer.

The section carries a note that v3 is unreleased and the list is still
growing.

## Keeping it current

`AGENTS.md` now states that a change breaking the public API adds its
own section to `MIGRATION.md` in the same pull request, the same way
parity work reconciles `sdk-compliance.yaml`. There is no pull request
template in `.github/`, so there was nothing to add a checkbox to.

Linked from the root `README.md` and
`packages/supabase_flutter/README.md`, next to the existing Guides and
Reference Docs links.

## Testing

Documentation only, no code changes. Every snippet in the guide was
type-checked against the workspace in a scratch file (`dart analyze`,
clean), which was then deleted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants