Centralize server/client environment detection by introducing a dedicated utility
file instead of repeating `typeof window === 'undefined'` checks across the codebase.
This improves code maintainability and consistency across 8 files with 15 occurrences.
Closes#30802