When performing an undo operation, ctx takes the value of 2 moves prior, instead of 1 move prior. This is particularly problematic when a move changes the phase. I've found that using
return {
...state,
G: restore.G,
ctx: last.ctx,
_undo: _undo.slice(0, _undo.length - 1),
_redo: [last, ..._redo],
};
seems to give the correct behavior.
When performing an undo operation, ctx takes the value of 2 moves prior, instead of 1 move prior. This is particularly problematic when a move changes the phase. I've found that using
seems to give the correct behavior.