You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(x-sdk): preserve message and conversation snapshots - #2077
Found while checking message and conversation updates.
💡 Background and Solution
setMessage and setConversation mutate the existing item before copying the array. A React.memo row receiving that item therefore keeps the same prop reference and displays the old content. The mutation also changes earlier snapshots and throws when the caller provides a frozen item. Removing an item similarly splices the array from the previous snapshot.
Create a new object for the updated item and copy the array before removal. Unchanged items keep their references, and partial updates still preserve existing fields.
Added store regressions for previous snapshots, frozen data, updater callbacks and unknown keys, plus hook tests covering memoized message and conversation rows. The existing setMessage test now waits for React to render the update.
Validation:
All 146 x-sdk tests pass, including 10 new cases. Eight of the new cases fail on the original implementation.
npm run tsc --workspace packages/x-sdk
npm run lint:script --workspace packages/x-sdk
Biome formatting check on the changed files.
📝 Change Log
Language
Changelog
🇺🇸 English
Fix useXChat and useXConversations updates leaving memoized rows stale and mutating previous state snapshots.
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 6 files.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 This is a ...
🔗 Related Issues
Found while checking message and conversation updates.
💡 Background and Solution
setMessageandsetConversationmutate the existing item before copying the array. AReact.memorow receiving that item therefore keeps the same prop reference and displays the old content. The mutation also changes earlier snapshots and throws when the caller provides a frozen item. Removing an item similarly splices the array from the previous snapshot.Create a new object for the updated item and copy the array before removal. Unchanged items keep their references, and partial updates still preserve existing fields.
Added store regressions for previous snapshots, frozen data, updater callbacks and unknown keys, plus hook tests covering memoized message and conversation rows. The existing
setMessagetest now waits for React to render the update.Validation:
npm run tsc --workspace packages/x-sdknpm run lint:script --workspace packages/x-sdk📝 Change Log
useXChatanduseXConversationsupdates leaving memoized rows stale and mutating previous state snapshots.useXChat和useXConversations更新后记忆化列表项不刷新、修改旧状态快照的问题。Summary by CodeRabbit