Conversation
There was a problem hiding this comment.
💡 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".
This can make the behavior more explicit and easy to understand. It can also make the overall app easier to inspect and maintain
There was a problem hiding this comment.
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
RoomIdtype fromstring | Uint8Arrayto juststring - Updated encoding to use
varStringinstead of conditionalvarString/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.
This PR enforces that
roomIdin the Loro Syncing Protocol must always be a UTF-8 string, removing the ambiguity and complexity of handling bothstringandUint8Arraytypes.Motivation:
Previously, the
RoomIdtype was defined asstring | 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
roomIdto a UTF-8 string, we simplify the protocol specification, streamline implementation efforts, and reduce potential conversion errors across different language and platform bindings.