Connection lost
Reconnecting. If you just saved something, check that it saved before trying again.
Server error
Reconnecting to the server. If you just saved something, check that it saved before trying again.
Testing for lost edits after a LiveView reconnect
A LiveView reconnect can bring back an old draft while the server loads a teammate’s newer edit. If Save checks against the version the server just loaded, the old draft can pass the optimistic lock check.
We test for this in Kogen Studio, the multiplayer workspace we’re building for our software factory. An overwritten edit there can change the instructions an agent gets on its next task. In this test, someone else has already saved when the draft comes back:
render_hook(project_view, "recover_contexts", %{
"project" => "Offline project draft",
"versions" => %{"project" => "0"}
})
refused = submit(project_view, "project", "Offline project draft")
assert refused.status == "Not saved: changed by someone else"
assert refused.current == "Competing project"
assert refused.draft == "Offline project draft"
The draft carries the version it started from. Save checks that version against the database, so Studio can keep the draft and show the teammate’s saved edit when they conflict.
If you use LiveView’s built-in form recovery, a hidden field lets you recover that version along with the text.
https://hexdocs.pm/phoenix_live_view/form-bindings.html#recovery-following-crashes-or-disconnects