Page MenuHomePhabricator

VisualEditor: Transaction with replaceMetadata then replace at the same offset doesn't rollback cleanly
Closed, InvalidPublicFeature

Description

This is kind of a ridiculous case, but it cost me an hour of debugging time, so documenting it here for posterity. It won't be a practical issue until we start composing transactions together.

Consider:

var data = ve.dm.example.withMeta,

oldDoc = new ve.dm.Document( ve.copyArray( data ) ),
newDoc = new ve.dm.Document( ve.copyArray( data ) ),
tx = new ve.dm.Transaction();

tx.pushRetain( 11 );
tx.pushReplaceMetadata( [], [ { metadata element here } ] );
tx.pushReplace( [] , [ 'a', 'b', 'c' ] );
ve.dm.TransactionProcessor.commit( newDoc, tx );
ve.dm.TransactionProcessor.rollback( newDoc, tx );

After running this, you'd expect oldDoc.metadata and newDoc.metadata to be equal, but they're not:

oldDoc.metadata[11].length;

4

newDoc.metadata[11].length;

5

When the transaction is rolled back, the metadata element that was added was never removed. I think this is because the content insertion pushes the metadata back, and then when the rollback tries to remove the metadata again, it can't find it. When the metadata replacement and content replacement are swapped, it works fine, so that's my workaround for now.


Version: unspecified
Severity: enhancement

Details

Reference
bz46138

Related Objects

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:18 AM
bzimport added a project: Technical-Debt.
bzimport set Reference to bz46138.
Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:13 AM
Aklapper removed a subscriber: TrevorParscal.
matmarex subscribed.

There are no more metadata ops since T56299.