hensei-web/components
Justin Edmund 778a1c70bd
Fix authentication state hydration mismatch (#433)
## Summary
- Fixed avatar showing anonymous for several seconds on page load
- Eliminated hydration mismatch for authentication state
- Header now shows correct user state immediately

## Root Cause
AccountStateInitializer was running client-side in useEffect AFTER
hydration, causing:
1. Server renders anonymous state
2. Client hydrates with anonymous state
3. useEffect runs and updates state (causing the flash)

## Solution
- Read auth cookies server-side in layout.tsx
- Pass initial auth data as props to AccountStateInitializer
- Initialize Valtio state synchronously before first render
- Client-side cookie reading only as fallback

## Changes
- Added server-side cookie parsing in layout.tsx
- Modified AccountStateInitializer to accept initial auth data props
- Made Header component reactive with useSnapshot from Valtio
- State initialization happens synchronously, preventing the flash

## Test plan
- [x] Avatar renders correctly on first load
- [x] No anonymous avatar flash when logged in
- [x] Login/logout still works properly
- [x] State updates are reactive in the header

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-03 17:34:34 -07:00
..
about Migrate about pages to App Router (#432) 2025-09-03 17:20:16 -07:00
AccountStateInitializer Fix authentication state hydration mismatch (#433) 2025-09-03 17:34:34 -07:00
auth Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
character Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
common Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
dialogs Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
ElementToggle Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
ErrorSection Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
extra Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
filters Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
head Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
Header Fix authentication state hydration mismatch (#433) 2025-09-03 17:34:34 -07:00
HovercardHeader Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
job Modernize Link components to Next.js 13+ patterns (#431) 2025-09-03 17:07:09 -07:00
LanguageSwitch Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
Layout Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
mastery Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
MentionList Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
party Modernize Link components to Next.js 13+ patterns (#431) 2025-09-03 17:07:09 -07:00
raids Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
reps Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
search Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
summon Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
toasts Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
uncap Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00
weapon Fix i18n migration to next-intl (#430) 2025-09-03 16:25:59 -07:00