Fix replication sent$ emitting documents in master format#8400
Open
Fix replication sent$ emitting documents in master format#8400
Conversation
The sent$ observable is typed as Observable<WithDeleted<RxDocType>> and must emit documents with `_deleted: boolean`. When using a custom deletedField, the upstream's row mutation in masterWrite swapped the field on the same row object that was later forwarded to processed.up, causing sent$ to emit docs with the master-format field (e.g. `is_deleted`) and an undefined `_deleted`. Create new row objects for the swap instead of mutating the originals.
Contributor
✅ Verify Test Reproduction: Tests FAILED without the fix (expected)This confirms the changed tests correctly reproduce the bug that the source changes fix. This workflow runs the changed tests without the source fix to verify they reproduce the bug. Show output |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR contains:
Describe the problem you have without this PR
The
sent$observable in the replication state was emitting documents in the master format (using the user-defineddeletedFieldlikeis_deleted) instead of the typedWithDeleted<RxDocType>format (with_deleted: boolean). This occurred because thedeletedFieldswap operation was mutating the same row object that was later forwarded tosent$subscribers, causing the format conversion to leak into the observable stream.What changed
Source Code Fix (
src/plugins/replication/index.ts):deletedFieldswap logic to create a new row object instead of mutating the originalnewDocumentStateandassumedMasterState, leaving the original row intactprocessed.up(which feedssent$) retains the_deletedformatTest Coverage (
test/unit/replication.test.ts):'sent$ must emit documents in WithDeleted format with _deleted field when deletedField is custom'deletedField)sent$observable emits documents in theWithDeletedformat (with_deleted: boolean)Test Plan
The added unit test covers the fix by:
deletedField(is_deleted)sent$emits theWithDeletedformat with_deletedfield_deleted=falseand_deleted=truecases work correctlyExisting tests continue to pass, and the new test specifically validates the corrected behavior.
https://claude.ai/code/session_0125qhPLxzvT8XV8ADq94zQZ