Hacker News new | ask | show | jobs
by orphea 849 days ago
jotaen explained it well. Sorry if I sounded mean, at some point you start to get tired of the websites that break the basic behavior of the browser.

Do not use history.pushState to update the URL if whatever is happening on the page doesn't count as navigation. Try to look into history.replaceState and see if it helps.

2 comments

I’d tend to agree that using the browser history doesn’t feel like the right solution for this kind of undo/redo functionality. In my mind, undo/redo actions are too fine-granular, and pollute the history, which can be very inconvenient.

Another potential approach could be to offer a custom-built widget for the undo/redo stack in the UI – in the simplest case, for example, a dropdown. It could also be persisted somewhere, e.g. in local storage, so that it isn’t lost when you navigate away.

Thanks for all the feedback! This community is incredible <3

Just pushed a fix that should resolve this while still maintaining state in the URL (using replaceState as suggested by OP).

For now it foregoes the undo/redo. I'll explore implementing it as a separate widget as you suggest in the future.

Not at all, I appreciate that you mentioned this since it seemed normal to me.

Thanks for the tip! I just pushed a fix that uses replaceState instead of push :)