[GH #6948] I've done something to break Undo

Tags: #<Tag:0x00007f343b308a10> #<Tag:0x00007f343b3088d0>

This works on the handsontable demo site, but I can’t figure out what I might have done to stop it working on my HotTable.

If I delete a block of text and then press ctrl+z it doesn’t reappear. I’ve doing one or two calls to ‘setDataAtCell’ after every change (as i’m maintaining a hidden metadata column in column zero that each change can effect) - do you think that’s causing it? If so can I do a ‘setDataAtCell’ that doesn’t count for undo purposes?

Calling setDataAtCell should not break Undo/Redo. In contrary - the programmatic data changes using that method are taken into account by Undo/Redo, as can be seen in this demo: https://jsfiddle.net/warpech/nsj3z8xf/7/. Actually this behavior is built-in and it is not possible to change it, as explained in an issue: https://github.com/handsontable/handsontable/issues/6948

Maybe you use loadData in your app? This method resets the Undo/Redo stack. I believe that updateSettings may reset the Undo/Redo stack depending on the property changed.

If that’s not helpful, I suggest to take a look at your DevTools console. Maybe there are some JS errors that break the app?

No JS errors BUT I have two HotTable’s on the same page and when you change the first one the second one updates. Could the update to the second one be destroying the undo/redo stack for the first?

Hi @HC289

do you use the ‘source’ parameter of the setDataAtCell method?

If you have some logic based on data being changed you may experience an endless call loop.

Can you share the logic of data change recognition?

I’ve managed to narrow this down to:

  • I have two <HotTable> on a page (Table A, Table B) using the react integration
  • I make three changes to Table A, undo works
  • I make three changes to Table A, in one of the handlers for this change I change the data attribute for TableB. What happens: I can no longer undo changes on Table A. Expected: I should still be able to undo Table A changes.

Is it possible setting the data for Table B is wiping Table A’s undo cache?

I’m looking at the handsontable afterChange code and I can see return instance.undoRedo.clear(); in the onAfterChange callback but surely that should only apply to one instance and not all HotTables right?

I’ve worked around it. Instead of doing:

const [tableBData, setTableBData] = useState([])

I’m now assigning a ref and doing:


This appears to do as I’d expect, the Undo buffer is preserved.

I’d really like to know why this happens though!

Hi @HC289

I would need to know how do you wanted to make the change in Table B’s data in the first place. If you would like to discuss that I’ve made a demo in React with v8.2.0 using two tables https://jsfiddle.net/4uzkd20p/ We can fill it with the logic and check it together.

Helpful thanks, the fiddle’s are useful. I’m trying to refactor it to be a modern functional component but struggling a bit, any ideas?

This is similar although not quite my issue: https://jsfiddle.net/ad0mcz5t/1/

After i change a cell in table1, table2 gets blanked. But when i press ctrl+z i can only go back one cell in table 1 - where’s the rest of my undo history gone? <-- is my question :slight_smile:

Hm… yes. I got the same result.

The undoRedo needs some re-check. My colleague is planning to go through all the connected issues (and we have some related to undo stack getting corrupted https://github.com/handsontable/handsontable/issues?q=is%3Aopen+is%3Aissue+label%3AUndo-redo+label%3A"Type%3A+Bug"+stack). After we will collect all the operations that are changing the undo stack we will be able to create an epic and push it further for the dev team to schedule.

I will add this case to https://github.com/handsontable/handsontable/issues/6948 and will update you on the status.

1 Like