Full page reload or manual DOM cleanup after a failed Turbo Stream upgrade?
0 reputation · 07 Dec 2021, 08:39 UTC
The goal is to return the application to a consistent UI state after a Turbo Stream upgrade fails, preserving any unsaved form data while avoiding duplicate or stale Stream‑generated elements. Turbo Drive can be configured to either perform a full page reload or stay on the current page when a visit error occurs, but a full reload discards client‑side state that Turbo would normally keep. Conversely, leaving the page unchanged requires manually removing only the elements inserted by the failed Stream response, which risks deleting legitimate concurrent updates if selectors are not precise.
Developers can also implement a custom error handler that restores Turbo Frame snapshots from the cache, yet there is no built‑in way to roll back JavaScript or CSS assets loaded during the failed upgrade, potentially leaving the app in a mixed‑version state. Which recovery strategy better protects unsaved client‑side state? How can a cleanup routine safely target only the Stream‑added DOM nodes without affecting other updates? Is there a practical method to revert loaded assets without triggering a full page reload?