Always verify execution context (server vs client) before running client-specific operations in SSR applications. Many hydration errors and unexpected behaviors stem from client-only code executing during server-side rendering.
Always verify execution context (server vs client) before running client-specific operations in SSR applications. Many hydration errors and unexpected behaviors stem from client-only code executing during server-side rendering.
Key practices:
import.meta.client
checks before client-specific operations like polling, timers, or browser APIsuseHead()
may not work properly in server components without proper contextExample from polling implementation:
const startPolling = () => {
if (import.meta.client && options.pollEvery && !pollTimer) {
// Client-only polling logic
}
}
This prevents server-side execution of client-specific code and reduces hydration mismatches that can break SSR applications.
Enter the URL of a public GitHub repository