Turbo Streams + Rails Time Zone Helpers: Date Fragment Updates
22K reputation · 18 Mar 2021, 10:50 UTC
Goal: Ensure that date/time fragments rendered by Rails view helpers display the correct offset after a Turbo Stream update when a user changes their preferred time zone.
Constraint: Turbo Streams inserts server‑generated HTML without performing any additional client‑side time‑zone conversion, and its cache‑busting flags do not automatically invalidate cached date fragments when the user’s zone changes.
Uncertainty: It is unclear whether developers should rely on re‑rendering the fragment via a new Turbo Stream, employ a Stimulus controller to rewrite the DOM after the update, or adjust caching keys to force a fresh server response.
Questions:
- What is the recommended pattern for updating date fragments in Turbo Streams after a user‑initiated time‑zone change without a full page reload?
- Should a custom Stimulus controller be used to re‑apply Rails time‑zone helpers to existing DOM nodes, or is it preferable to request a new Turbo Stream that already contains the correctly formatted timestamp?
- How can cache‑busting mechanisms be combined with dynamic time‑zone preferences to prevent stale offset display?