View on GitHub

guides

Handle conflicts consciously, not accidentally

Background

So what’s a conflict? - in our case conflict is said to happen when our application tries to update an object which state changed in between the last fetch and now. It might have been edited, it might have been removed.

You might think that this is an edge case - it’s not. Your application will be used by multiple people on the same account, by the same user in multiple tabs, by the same user on different devices at the same time. You might want to add live websocket connection to propagate changes as they happen.

All of these cause conflicts.

Rules

How to test this behavior?

Explicitly check this behavior e.g. by using your component in to tabs or on two devices at the same time.

Implementation hints

Conflict detection

If there is an autoincrementing ‘version_id’ field - remember to send it to the backend alongside the changes.

How to be able to make this kind of decisions in your error handling logic

Your ‘draft’ objects implementation should have the ability to check which fields were changed by the user, and which were not. This gives you a lot of power.

Prefer PATCHing diff over PUTting the whole entity.

Care about state not single actions

Usual conflict handling scenario