Skip to content

SaveState/LoadState discards command metadata: timestamps reset to load time, ChangeSize to 1, CustomData lost #77

Description

@matt-edmondson

What's wrong

JsonUndoRedoSerializer serializes each command's Metadata. On load, though, PlaceholderCommand (UndoRedo/Services/JsonUndoRedoSerializer.cs:~186) passes only ChangeType and AffectedItems to the BaseCommand constructor, which builds a fresh ChangeMetadata with:

  • DateTimeOffset.Now,
  • a size of 1,
  • no CustomData.

The deserialized metadata is thrown away, although the comment at around line 104 says the placeholder "preserves metadata".

Failure scenario (reproduced with a temporary MSTest)

Execute DelegateCommand(..., size: 42), then SaveStateAsync, then LoadStateAsync into a new service:

orig   size=42 ts=...54.3085987
loaded size=1  ts=...54.4617403

After a reload, any history or change-visualization UI (GetChangeVisualizations) shows every change as having happened at load time with size 1, and any CustomData the app attached is gone.

Suggested fix

BaseCommand.Metadata is virtual with a protected setter. In PlaceholderCommand's constructor, assign the deserialized ChangeMetadata: Metadata = metadata;. Or override Metadata to return it.

Acceptance: a round-trip test asserting that Timestamp, ChangeSize and CustomData survive save and load.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions