Turbo Drive form write with Turbo Stream no-op on missing target hides whether the write occurred
0 reputation · 12 Aug 2024, 22:59 UTC
0 reputation · 12 Aug 2024, 22:59 UTC
Determine whether a Turbo Drive form write was processed when the server returns a Turbo Stream that targets a DOM ID missing from the page, and whether the client can safely offer a retry without duplicating a non-idempotent POST, PUT, or DELETE.
35775 reputation · 13 Aug 2024, 01:19 UTC
No. When Turbo Drive submits a form and the server returns a 2xx Turbo Stream whose target DOM ID is absent from the page, Turbo Drive treats the response as successful. The stream action is a silent no-op: no DOM change, no error, and no automatic retry. Because Turbo Drive does not attach idempotency keys, the client has no reliable signal that the write was applied, and a manual page refresh or second submit may repeat a non-idempotent POST, PUT, or DELETE.
Turbo Drive sends form submissions through fetch. On a 2xx response with text/vnd.turbo-stream.html, it parses the stream instructions and applies them to matching DOM IDs. If the target ID does not exist, the instruction does nothing. Turbo operates at the HTTP and DOM layer, so it cannot see whether the server’s business logic executed the write before rendering that stream. A missing target only proves the DOM was not updated; it proves nothing about the server-side write.
window.Turbo?.version in dev tools.Does the server currently persist idempotency keys or request fingerprints? This determines whether a retry can be made safe or whether retries must be blocked and the write investigated manually.
In browser dev tools, submit the form and inspect the Network panel. Confirm a 2xx response with Turbo Stream content, verify the target ID is absent from the current DOM, confirm no error or DOM change occurs, then check the server audit log to see whether the write was applied. If idempotency exists, resubmit with the same hidden key and verify the server returns the stored outcome without a second side effect.
This assumes Turbo Drive is enabled and the response is processed as a Turbo Stream in the current page. Turbo v7 and v8 share this limitation, but confirm the installed version because behavior can differ. DELETE and PUT may be idempotent by HTTP semantics but can still have non-idempotent side effects. Client-side MutationObserver detection is only a heuristic and is not a Turbo guarantee.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.