Skip to content

Conversation

@grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Dec 11, 2025

Description

This PR makes the ref field optional in the Message class to match the JavaScript SDK behavior. The ref field is now nullable (String?) and optional in the constructor, allowing null refs in scenarios like heartbeats.

Context

The JavaScript SDK recently fixed an issue with message serialization in the Realtime library to properly handle null/undefined ref and join_ref fields when encoding messages (PR #1862).

Changes

  • Changed ref field from String to String? (nullable)
  • Made ref parameter optional in the Message constructor
  • Updated toJson() method to conditionally include ref only when not null (consistent with joinRef handling)
  • Added comprehensive test coverage for null ref scenarios

Testing

  • ✅ All new tests pass (6/6)
  • ✅ All existing tests pass (26/26 in socket_test.dart)
  • ✅ No compilation errors
  • ✅ Backward compatible: existing code that provides ref continues to work

Breaking Changes

This is a minor breaking change since ref was previously required. However:

  • Existing code that provides ref will continue to work
  • Only code that creates Messages without ref will benefit from this change
  • This aligns with the JavaScript SDK behavior

Related

Make the ref field nullable (String?) and optional in the Message constructor
to match JavaScript SDK behavior. This allows null refs in scenarios like
heartbeats and aligns with the JavaScript SDK implementation.

- Changed ref from String to String?
- Made ref optional in constructor
- Updated toJson() to conditionally include ref only when not null
- Added comprehensive tests for null ref scenarios

Closes SDK-531
@coveralls
Copy link

coveralls commented Dec 11, 2025

Pull Request Test Coverage Report for Build 20148486612

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 79.876%

Totals Coverage Status
Change from base Build 20143869923: 0.0%
Covered Lines: 3350
Relevant Lines: 4194

💛 - Coveralls

@grdsdev grdsdev requested review from a team and Vinzent03 December 11, 2025 21:38
@grdsdev grdsdev merged commit 0b194e4 into main Dec 11, 2025
15 checks passed
@grdsdev grdsdev deleted the guilherme/sdk-531-flutter-verify-optional-refs-handling-in-message branch December 11, 2025 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants