4 ms·
This is solid advice. Another common trick is to disable the submit event when the submit button is clicked for the first time, preventing two requests from fir
by rectangletangle 8y ago
This is solid advice. Another common trick is to disable the submit event when the submit button is clicked for the first time, preventing two requests from firing, when the user double clicks. Then re-enable the event, if the request fails. Ideally this is done in addition to server side nonce validation, and not as the only preventative measure, because browser differences, or network issues could cause a double request (more likely if the HTTP GET method is used, instead of a proper POST). Regardless server and client side techniques should be used together to create a better UX, similar to using both client and server side email format validation.
- deleted 8y ago[deleted]
- PinkMilkshake 8y agoThat's only a partial solution. It may be a user agent or a queuing system (or anything else sitting between a person clicking the button and where the final transaction is recorded) that attempts a retry.
- digitaLandscape 8y agoI don't like this because in practice sites usually fail to re-enable the submit button if something goes wrong. Just let the user submit multiple requests if they want to retry, don't take that away from them, just make it harmless.
- jen729w 8y agoNewbie programmer here, but even I am already implementing finite state machines which handily fix this sort of issue. Any sort of UI without them now feels archaic.
- hood_syntax 8y agoAgree 100%. If you don't have explicit state transitions in a UI, you're asking for trouble. I think some people don't realize how much harder they make it on themselves by not setting clear boundaries; they see the up front cost and balk, when it saves a non-trivial amount of headache in the future, not to mention reducing mental overhead when you've got the structure hashed out.
- digitaLandscape 8y agoMeh. The logic still applies: on a bad network, the first request can hang for half a minute when a retry would get lucky and go through immediately. Don't handcuff your users for no benefit, just because you can't write a well-behaved backend.
- BoiledCabbage 8y agoRestricting what the client can do isn't idempotency. Allowing the user to perform the same action (make the same api-call) multiple times, Nd your API coalesce them as if it were 1, is. The point and benefit of idempotency on this scenario is that you silently support "bad" behavior.
- notatoad 8y agodisabling the submit button is a nice UI feature to indicate idempotency, but it's not the same thing as the function actually being idempotent. both are important.
- qoi2ijds0 8y agoIMO disabling buttons causes more trouble than it's worth - you can never guarantee the user hasn't clicked twice (because don't forget the code that disabling the button in the first place is relying on an event firing that tells you the button was clicked - this doesn't mean 2 events can't be queued before the event handler is called), and then you need a whole chunk of code around re-enabling the button depending on what has happened after the fact which is then a big source of bugs.
- genericid 8y agoThis is basically client-side validation.