Repository navigation
refactor(realtime)!: clean up connection naming on RealtimeClient - #1404
Merged
Merged
Conversation
This was referenced Jun 12, 2026
Closed
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
Contributor
📝 WalkthroughWalkthroughThe realtime client renames ChangesRealtime connection API rename
Estimated code review effort: 2 (Simple) | ~15 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
spydon
force-pushed
the
lukasklingsbo/sdk-583-realtime-v3-renames
branch
from
August 5, 2026 13:43
c3ea0b8 to
40058c5
Compare
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
force-pushed
the
lukasklingsbo/sdk-583-realtime-v3-renames
branch
from
August 5, 2026 13:52
40058c5 to
e9713f8
Compare
`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
marked this pull request as ready for review
August 5, 2026 14:18
This was referenced Aug 5, 2026
Tr00d
approved these changes
Aug 6, 2026
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.
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.
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
connabbreviationRealtimeClient.connconnectionRealtimeClient.connStateconnectionState(see below)RealtimeClient.onConnMessageonConnectionMessagePrivate and local:
_onConnOpen/_onConnClose/_onConnErrorbecame_onConnectionOpen/_onConnectionClose/_onConnectionError, and thelocalConnlocal inconnect()becamelocalConnection.Also the shortenings the rename itself did not reach: the heartbeat timeout log message now reads "Attempting to re-establish connection", a
channel_testdescription that said "via ws conn", andchanParamson the test stub'schanneloverride (renamed toconfig, matching theRealtimeClient.channelsignature it overrides).Collapse the two socket-state accessors
Spelling out
connStateleft it one word away from the existingString get connectionState, and both carried the same information. The stringly typed getter is gone and the typed field takes the name:For the string form use
connectionState?.name; for the common caseisConnectedis unchanged.Singularize the enum
SocketStatesis nowSocketState, 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→connectionRealtimeClient.onConnMessage→onConnectionMessageRealtimeClient.connState→connectionStateRealtimeClient.connectionStatechanges type fromStringtoSocketState?. This one is a silent change for anyone reading it as a string, so it is worth calling out in the release notes.SocketStates→SocketStateRenames and one removal. No behaviour change.
Capability matrix
RealtimeClient.connection,RealtimeClient.onConnectionMessage, andSocketStateare registered insdk-compliance.yaml.RealtimeClient.connectionStatekeeps its name and its existing entry.Notes
mainnow that feat(realtime): add support for protocol format 2.0.0 #1397 has merged.v3(tracked in ☂️ v3 tracking issue #1278). It still targetsmain; happy to flip the base if that is still the plan.PostgresTypesamong them is actually exported, so three of the four can land before v3; left out here to keep this PR scoped.Tests
realtime_client203 passing,supabase135 passing,supabase_flutter63 passing.dart analyzeanddart formatclean. The capability matrix symbol and schema checks were run locally againstmainand pass.Summary by CodeRabbit
Breaking Changes
SocketState,connection,connectionState, andonConnectionMessage.Bug Fixes
Documentation