Skip to content

feat(sync): Add checks when containerId is provided#67

Open
kulla wants to merge 1 commit into
loro-dev:mainfrom
kulla:z4uIW-kulla-2025-12-28-17-17
Open

feat(sync): Add checks when containerId is provided#67
kulla wants to merge 1 commit into
loro-dev:mainfrom
kulla:z4uIW-kulla-2025-12-28-17-17

Conversation

@kulla

@kulla kulla commented Dec 28, 2025

Copy link
Copy Markdown
Contributor

I run into an issue providing a container ID of an detached container. With the implementation before I got an Uncaught TypeError since there is no type check whether getContainerId() returns a container so that map.get() cannot be called (see

const map = containerId
? (doc.getContainerById(containerId) as LoroMap<LoroNodeContainerType>)
: doc.getMap(ROOT_DOC_KEY);
let isInit = false;
if (map.get("nodeName") == null) {
). I took me a while to find the issue.

Thus I suggest to add some type checks when containerId is provided with appropriate error message. This should result in a better developer experience.

Note: Due to #66 I haven't checked my code.

Copilot AI review requested due to automatic review settings December 28, 2025 18:20

Copilot AI left a comment

Copy link
Copy Markdown

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 adds validation checks when a containerId is provided to updateLoroToPmState() to prevent Uncaught TypeError exceptions when dealing with detached or invalid containers. The changes improve error handling and developer experience by providing clear error messages.

Key Changes:

  • Extracted container retrieval logic into a dedicated getContainer() helper function with proper validation
  • Added null check for non-existent containers with helpful error message
  • Added type validation to ensure the container is a LoroMap instance

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

Comment thread src/lib.ts Outdated
function valueToAttrs(
value: Value | Attrs | null | undefined,
): Attrs | null {
function valueToAttrs(value: Value | Attrs | null | undefined): Attrs | null {

Copilot AI Dec 28, 2025

Copy link

Choose a reason for hiding this comment

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

This formatting change appears unrelated to the PR's stated purpose of adding checks for containerId validation. Consider keeping formatting changes in separate commits for clearer git history.

Copilot uses AI. Check for mistakes.
I run into an issue providing a container ID of an detached container.
With the implementation before I got an `Uncaught TypeError` since there
is no type check whether `getContainerId()` returns a container so that
`map.get()` cannot be called. I took me a while to find the issue.

Thus I suggest to add some type checks when `containerId` is provided
with appropriate error message. This should result in a better developer
experience.
@kulla

kulla commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Ping @ocavue for merging 😄

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.

3 participants