diff --git a/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeFamily.ts b/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeFamily.ts index 57afe5c27d27..4b1df18ea467 100644 --- a/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeFamily.ts +++ b/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeFamily.ts @@ -211,16 +211,12 @@ export class ModularChangeFamily const { revInfos, maxId } = getRevInfoFromTaggedChanges(changes); const idState: IdAllocationState = { maxId }; - return changes.reduce( - (change1, change2) => - makeAnonChange(this.composePair(change1, change2, revInfos, idState)), - makeAnonChange({ - fieldChanges: new Map(), - nodeChanges: new Map(), - nodeToParent: new Map(), - nodeAliases: new Map(), - crossFieldKeys: newCrossFieldKeyTable(), - }), + if (changes.length === 0) { + return makeModularChangeset(); + } + + return changes.reduce((change1, change2) => + makeAnonChange(this.composePair(change1, change2, revInfos, idState)), ).change; } diff --git a/packages/dds/tree/src/test/feature-libraries/optional-field/optionalChangeRebaser.test.ts b/packages/dds/tree/src/test/feature-libraries/optional-field/optionalChangeRebaser.test.ts index 9df35f818a75..9c9e17008d4e 100644 --- a/packages/dds/tree/src/test/feature-libraries/optional-field/optionalChangeRebaser.test.ts +++ b/packages/dds/tree/src/test/feature-libraries/optional-field/optionalChangeRebaser.test.ts @@ -222,10 +222,12 @@ function rebaseComposedWrapped( change: TaggedChange, ...baseChanges: TaggedChange[] ): WrappedChangeset { - const composed = baseChanges.reduce( - (change1, change2) => makeAnonChange(composeWrapped(change1, change2)), - makeAnonChange(ChangesetWrapper.create(Change.empty())), - ); + const composed = + baseChanges.length === 0 + ? makeAnonChange(ChangesetWrapper.create(Change.empty())) + : baseChanges.reduce((change1, change2) => + makeAnonChange(composeWrapped(change1, change2)), + ); return rebaseWrapped(change, composed, metadata); } diff --git a/packages/dds/tree/src/test/feature-libraries/sequence-field/utils.ts b/packages/dds/tree/src/test/feature-libraries/sequence-field/utils.ts index 011185ebf316..7dfb60e71280 100644 --- a/packages/dds/tree/src/test/feature-libraries/sequence-field/utils.ts +++ b/packages/dds/tree/src/test/feature-libraries/sequence-field/utils.ts @@ -92,15 +92,15 @@ export function composeDeep( ): WrappedChange { const metadata = revisionMetadata ?? defaultRevisionMetadataFromChanges(changes); - return changes.reduce( - (change1, change2) => - makeAnonChange( - ChangesetWrapper.compose(change1, change2, (c1, c2, composeChild) => - composePair(c1.change, c2.change, composeChild, metadata, idAllocatorFromMaxId()), + return changes.length === 0 + ? ChangesetWrapper.create([]) + : changes.reduce((change1, change2) => + makeAnonChange( + ChangesetWrapper.compose(change1, change2, (c1, c2, composeChild) => + composePair(c1.change, c2.change, composeChild, metadata, idAllocatorFromMaxId()), + ), ), - ), - makeAnonChange(ChangesetWrapper.create([])), - ).change; + ).change; } export function composeNoVerify(