Skip to content

fix: replay_bloc keeps more undo history than limit after limit is lowered #4901

Open

Description

@ChandraChaan

Description

ReplayCubit/ReplayBloc (and the mixins) expose a limit setter: "Sets the internal undo/redo size limit." When limit is lowered after history has built up, the history is never trimmed to the new limit:

  • Setting limit doesn't trim anything, so the next undo() calls go back further than the limit allows.
  • After the next emit, _ChangeStack.add removes only one old entry (if, not while), so the history stays above the limit.

Steps To Reproduce

final cubit = CounterCubit(); // ReplayCubit<int>, no limit
cubit
  ..increment() // 1
  ..increment() // 2
  ..increment() // 3
  ..limit = 1
  ..undo()
  ..undo();

Expected: states 1, 2, 3, 2 (only one undo is allowed).
Actual: states 1, 2, 3, 2, 1.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions