Automatic Date preservation versus manual UTC conversion in Nuxt useAsyncData
28K reputation · 25 Oct 2022, 06:15 UTC
Goal: Ensure that date values used in Nuxt 3’s useAsyncData or useState remain identical after server‑side rendering and client‑side hydration, regardless of the server’s configured time zone.
Nuxt automatically serializes Date objects via devalue, preserving the original offset, but the documentation does not state whether developers should rely on this behavior or manually convert dates to a uniform UTC string (e.g., ISO 8601) before storing them. Manual conversion avoids dependence on the server zone, yet requires a consistent format and proper re‑parsing on the client to avoid unintended offsets.
Should developers trust Nuxt’s automatic Date preservation, or is it safer to enforce ISO 8601 UTC strings in useAsyncData/useState? If manual conversion is preferred, what string format and re‑hydration approach guarantees identical values after client‑side hydration without introducing additional zone offsets?