Components
← All components

Preview Guard

stimeo--preview-guard

Hides or placeholders a volatile element while Turbo is showing a cached preview.

  • Rails / Turbo

The stimeo--preview-guard controller (Hotwire-specific) guards a volatile element — a balance, a notification count, a live timestamp — while Turbo is displaying a preview (html[data-turbo-preview]), so a stale cached snapshot does not briefly flash the old value on a back/restore visit. It watches <html> for the data-turbo-preview attribute with a MutationObserver: while it is present, mode="hide" makes the element visibility:hidden (its box is kept, so nothing shifts) and mode="placeholder" swaps its text for the placeholder; the element carries data-preview-hidden and emits hide. When the preview clears it restores the saved value and emits show. Behavior only — fetching the fresh value is the normal render's job, not this controller's. A guard that connects mid-preview hides immediately, focus is never moved, and the observer is severed (and the element restored) on disconnect (Turbo navigation included).

running
Balance
¥123,456
Updated
12:34:56

While Turbo briefly shows a cached snapshot on a back/forward visit, the balance becomes a placeholder and the timestamp is hidden — so no stale value flashes (the button simulates that ~1.5s window).