Inconsistent behavior of window.alert() during Nuxt navigation guards
0 reputation · 21 Jul 2024, 09:33 UTC
In Nuxt 3, triggering native window.alert() calls within navigation guards or lifecycle hooks can lead to unpredictable results across different environments. Because Nuxt performs both server-side rendering (SSR) and client-side hydration, the timing and execution of these calls vary relative to the application state.
When an alert is placed inside a global middleware or a specific route guard, it may be suppressed if the code executes on the server, or it might trigger multiple times during client-side hydration. This is particularly problematic when trying to provide immediate user feedback without interrupting state transitions.
How does Nuxt manage the execution of browser-specific APIs during the transition from SSR to hydration? Is there a specific mechanism to ensure an alert fires exactly once on the client side during navigation?