welcome to the forum.
If I understand your requremntes correct, this is a common problem.
You might set a lock first (pessimistic) and block other clients.
Or you use a 'version counter' and check the counter before you change (in the same transaction).
The second approach is better as it will not block other and if the browser or connetion fail you must not cleanup the lock.