Add unit test and fix for schema.LoroTree example from README docs (#65)#67
Add unit test and fix for schema.LoroTree example from README docs (#65)#67mtmacdonald wants to merge 1 commit intoloro-dev:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const required = | ||
| schema.options.required !== undefined | ||
| ? schema.options.required | ||
| : true; | ||
| const value = required ? [] : undefined; | ||
| if (value === undefined) return undefined; |
There was a problem hiding this comment.
Avoid defaulting empty tree when snapshot omits it
This change makes getDefaultValue return [] for loro-tree when required is unset, which means Mirror's in-memory state will always include an empty tree even if the doc has no tree nodes. However, buildRootStateSnapshot only includes trees when they are non‑empty, so when checkStateConsistency is enabled, any setState call that doesn’t add tree nodes will now throw State diverged because the state has tree: [] but the snapshot omits it. Consider either keeping the default undefined for empty trees or updating the snapshot logic to include empty trees so the invariants still hold.
Useful? React with 👍 / 👎.
Fixes #65. Adds a unit test with the
schema.LoroTreeexample from the README docs, and resolves making the example code pass. Previously I gotTypeError: Cannot read properties of undefined (reading 'push')when trying to invoke the example.Would be great if I could have a review on this (I'm not too deep into the internals of this repo), and feedback is welcome if there's a better resolution (like fixing the docs example). Thank you!