canUndo() returns incorrect value

I am calling canUndo() to find out when there is no more transactions to undo. Before there were any changes made in the diagram the value returned is false. Once an transaction is done the value returned is true and stays true no matter how many times I call the function commandHandler.undo().
I see that all the changes were undone also in the diagram and canUndo() was still true. I tried using both undoManager.canUndo() and commandHandler.canUndo() with the same result.

		name: 'undo-template',
		locationSpot: go.Spot.Center,
		resizable: false,
		selectionAdorned: false,
		cursor: 'pointer',
		mouseEnter: (_e: go.InputEvent, obj: go.Part) => {
		mouseLeave: (_e: go.InputEvent, obj: go.Part) => {
		click: (_e: go.InputEvent, obj: go.Part) => {
				if(!mainDiagram.commandHandler.canUndo()){//This line is always false because canUndo() is always true
					//change icon
		goMake(go.Picture, {
			name: 'undo-icon',
		goMake(go.Shape, goObjectTypes.Rectangle, {
			name: 'backgroundShape',

I am unable to reproduce that behavior in either of the two samples that I tried.

What do your mouse… event handlers do? I’m wondering if they modify the diagram/model outside of a transaction.