Skip to content

fix!: enforce to use string for room-id#27

Merged
zxch3n merged 5 commits intomainfrom
fix-room-id
Nov 20, 2025
Merged

fix!: enforce to use string for room-id#27
zxch3n merged 5 commits intomainfrom
fix-room-id

Conversation

@zxch3n
Copy link
Copy Markdown
Member

@zxch3n zxch3n commented Nov 20, 2025

This PR enforces that roomId in the Loro Syncing Protocol must always be a UTF-8 string, removing the ambiguity and complexity of handling both string and Uint8Array types.

Motivation:
Previously, the RoomId type was defined as string | Uint8Array, leading to redundant conversion logic in various parts of the codebase (e.g., simple-server.ts, client-side message handling) and making the protocol less straightforward to implement.

By standardizing roomId to a UTF-8 string, we simplify the protocol specification, streamline implementation efforts, and reduce potential conversion errors across different language and platform bindings.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/loro-websocket/src/server/simple-server.ts Outdated
This can make the behavior more explicit and easy to understand. It can also make the overall app easier to inspect and maintain
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR standardizes the roomId field in the Loro Syncing Protocol to always be a UTF-8 string, eliminating the previous ambiguity of supporting both string and Uint8Array types. This simplification removes redundant type conversion logic across the codebase and makes the protocol more straightforward to implement.

  • Changed RoomId type from string | Uint8Array to just string
  • Updated encoding to use varString instead of conditional varString/varBytes
  • Removed all conversion logic (bytesToHex, TextDecoder().decode() calls) throughout the codebase

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
protocol.md Updated documentation to specify varString for room ID instead of varBytes
packages/loro-protocol/src/protocol.ts Simplified RoomId type definition to just string
packages/loro-protocol/src/encoding.ts Changed encode/decode to use varString for room ID and removed conditional type handling
packages/loro-websocket/src/server/simple-server.ts Removed roomIdToString() helper and bytesToHex import, simplified getRoomKey()
packages/loro-websocket/src/client/index.ts Removed all TextDecoder().decode() conversions for room ID handling
packages/loro-websocket/test-wrappers/recv-index.ts Changed from Buffer.from(roomId) to direct string usage
packages/loro-protocol/tests/encoding.test.ts Updated test fixtures to use string room IDs
packages/loro-protocol/tests/encoding.snap.test.ts Updated test fixtures to use string room IDs
packages/loro-protocol/tests/snapshots/encoding.snap.test.ts.snap Updated binary snapshots to reflect UTF-8 string encoding
packages/loro-protocol/README.md Updated example to use string directly instead of TextEncoder

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/loro-protocol/src/encoding.ts Outdated
Comment thread packages/loro-protocol/src/encoding.ts Outdated
@zxch3n zxch3n changed the title fix: enforce to use string for room-id fix!: enforce to use string for room-id Nov 20, 2025
@zxch3n zxch3n merged commit 2eeea76 into main Nov 20, 2025
2 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 20, 2025
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.

2 participants