fix(onboarding): guard window access in SSR (#351)

## Problem

Production SSR crashes repeatedly when rendering the Onboarding page:

```
ReferenceError: window is not defined
  at Onboarding (/app/bootstrap/ssr/assets/index-BEtdcHXd.js:2295)
```

The `useMemo` reading `?step=` from the URL accessed
`window.location.search` directly, which fails during Inertia SSR.

Observed ~7+ times in production logs between 18:35–21:37 UTC.

## Fix

Add `typeof window === 'undefined'` guard before reading the URL.
Returns `undefined` on the server so the step initializer falls back to
default behavior; client hydration re-runs and reads the URL.

## Related logs

- `Inertia\Ssr\SsrException` — Onboarding page
- Other SSR-touching files (`welcome.tsx`, `auth/login.tsx`) verified
safe (window inside `useEffect` or already guarded).
This commit is contained in:
Víctor Falcón 2026-05-05 08:45:44 +01:00 committed by GitHub
parent f800847591
commit b1709b714e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -71,6 +71,9 @@ export default function Onboarding({
// Read ?step= from URL to allow deep-linking into a specific step
const initialStep = useMemo((): OnboardingStep | undefined => {
if (typeof window === 'undefined') {
return undefined;
}
const params = new URLSearchParams(window.location.search);
const step = params.get('step') as OnboardingStep | null;
return step && VALID_STEPS.includes(step) ? step : undefined;