FIX: discourse-reactions rollback not working

The discourse-reactions plugin has a rollback function, when the toggle.json request fails, the page should rollback the reactions to the original state.

However, the function is broken, and the original _rollbackState() function never works as the state itself changes when toggleReaction is called. And the reaction state never goes back without refreshing/reloading the window, leading to the heart/reactions leaving on the page even when the request failed.

This commit fixs this by adding a new function _captureState(), keeping the state in a const value, and revert it to the page data when necessary.

2 Likes

Thank you, I have approved :+1:

2 Likes

@martin Please take a look, it seems the rspec is failing due to an unrelated issue. :heart:

It was just a flaky spec, I have merged the PR now :slight_smile:

2 Likes