Skip to content

Checkpoints lose pending changes when the other data domain returns to its checkpoint state #296

Description

@dajiaohuang

Describe the bug

Cancelling the pending changes in one data domain can make Checkpoints treat the Store as unchanged even though the other domain still has changes. The next addCheckpoint() returns the previous ID, and undo does not revert the remaining change.

Steps to Reproduce the Bug or Issue

import {createCheckpoints, createStore} from 'tinybase';

const store = createStore().setValue('count', 0).setCell('pets', 'fido', 'age', 0);
const checkpoints = createCheckpoints(store);
store.setValue('count', 1);
store.setCell('pets', 'fido', 'age', 1);
store.setCell('pets', 'fido', 'age', 0);
console.log(checkpoints.addCheckpoint()); // '0', rather than a new checkpoint
checkpoints.goBackward();
console.log(store.getValue('count')); // 1, expected 0
checkpoints.destroy();

The symmetric case also fails: keep a cell change pending while changing a keyed value and then restoring it. Creating and deleting the temporary cell/value exhibits the same problem.

Expected behavior

The Store should remain between checkpoints until both tabular and keyed-value changes are cancelled. A new checkpoint should retain the outstanding change for undo and redo.

Platform

  • Windows, Node.js v24.14.1
  • Current main: f09e5a3b74ea16b6fac93439be34cc3f954f1e7c (package version 9.7.0)
  • Reproduced against source; regression tests also run against the native test build.

Additional context

Both listener paths call storeUnchanged() when their own delta map becomes empty without checking the other delta map. Checking both maps preserves the existing API and only changes this incorrect mixed-data checkpoint transition.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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