-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: preserve order in patch serialization #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
rexxars
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear to me if this actually fixes any current bugs? I understand that it's needed for later changes, but if there are potential bugs in the current implementation, we should ensure this one has a failing test (that gets fixed by this PR)
dda33fd to
d4a9699
Compare
61a3ffc to
5067260
Compare
d4a9699 to
7c922f7
Compare
Merge activity
|
Change patch serialization from batch processing to sequential processing to preserve the original order of operations while still optimizing consecutive compatible patches. - Process patches one by one instead of grouping by type - Combine consecutive set/diffMatchPatch and unset operations - Keep insert operations separate to maintain precision - Ensure patch application order matches generation order
7c922f7 to
f391c3c
Compare

This PR refactors the internal
serializePatchesfunction to use a recursive approach. The primary goal of this change is to better preserve the original order of operations as they are generated bydiffItemwhen they are grouped intoSanityPatchOperations.Previously,
serializePatcheswould filter all patches by type (set, unset, insert, dmp) and then combine them. This could lead to a reordering of operations if, for example, asetoperation was diffed before anunsetoperation that should logically follow it.The new recursive approach processes patches one by one:
setoperations can be combined into a singleset: {...}object).insertoperations always result in a new patch object being emitted, as they are not typically batched with other operation types in the same way.Key Changes:
serializePatches:serializePatchesfunction now takes an optionalcurr?: SanityPatchOperationparameter to carry the currently accumulating patch object.patchesarray:setanddiffMatchPatch: Ifcurris undefined or of a different type, a newcurris started. Otherwise, the operation is merged into the existingcurr.unset: Similar logic toset, but merges intocurr.unset[].insert: Ifcurrexists, it's emitted first, then theinsertoperation is emitted as a new patch object.set, thenunset, thensetagain, these will be serialized into distinct patch operation objects, preserving that logical sequence.SanityPatchMutation[]array where previously operations might have been grouped less granularly or in a different order. For example, asetfollowed by adiffMatchPatchwill now be two separate entries in theSanityPatchMutation[]array if they were generated in that order bydiffItem.Rationale:
unsethappening before aseton a related path) as determined by the diffing logic is maintained in the serialized output. This can be important for the logical application of patches, especially in more complex scenarios or when patches might be manipulated or inspected before application.This change primarily affects the internal serialization and the structure of the output array in snapshots, aiming for a more robust and order-preserving serialization.