fix(frontend): eliminate profile hydration drift and harden stored me… - #529
Merged
MaryammAli merged 1 commit intoAug 18, 2026
Conversation
…tadata Renders public profile pages, header navigation, and countdown widgets deterministically on server and client so users no longer see flicker, hydration mismatches, or stale content across refreshes. Stored profile metadata is now validated and merged safely, recovering gracefully from malformed local data. Test infrastructure (pre-existing failures): - vitest.config.ts: remove duplicate setupFiles key (empty array shadowed vitest.setup.ts) so jest-dom matchers load, fixing the SigningSummary failures. - usePersistentState.ts: hold serialize/deserialize in refs so inline (unstable) callback identities no longer re-trigger the hydration effect into an infinite re-render loop; fixed its test (jest -> vi, correct import path). Metadata consistency: - types/profile.ts: add ProfileMetadata, PROFILE_METADATA_DEFAULTS, and sanitizeProfileMetadata (hex color, absolute http(s) avatar URL, trimmed + length-capped bio/handles; never throws). - lib/api.ts: readStoredProfileMetadata + safe merge with per-field sanitization; corrupt/non-object localStorage entries are removed on read; storage keys canonicalized to lowercase in getProfile/saveProfile. - app/[username]/page.tsx: reset state per username change, avatar onError fallback to initial, consistent error copy for invalid/private/not-found states, role=status + role=alert + aria-live. Hydration-safe time/locale rendering: - hooks/marketplaceApi.ts: export standalone formatCountdown(date, now?) mirroring the provider implementations. - components/UsernameCard.tsx: mounted-pattern 'now' state (updated every 30s) replaces Date.now() at render to keep countdown/urgency/UrgencyBar identical between SSR and client. - lib/i18n.ts: init deterministically in 'en' on server and client; components/Header.tsx restores the saved language post-hydration and fixes the leading-space aria-label. Other: - app/manifest.ts: add lang/dir and complete shortcut icon type/purpose metadata. Pre-existing type/build errors fixed so the app compiles: - app/page.tsx: drop dead fetchListings warm-up (import never existed). - app/dashboard/page.tsx: consume fetchUserBids/fetchUserListings via MarketplaceApiProvider + useMarketplaceApi(). - app/marketplace/page.tsx: remove duplicate showWatchlistOnly state and import useRef. - components/PWAHandler.tsx: pass route/extra context to errorReporter (valid ErrorContext). Verification: full vitest suite green (12 files, 105 tests) and tsc --noEmit -p tsconfig.test.json clean. New unit tests cover sanitizeProfileMetadata and api.ts merge/recovery behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…tadata
Renders public profile pages, header navigation, and countdown widgets deterministically on server and client so users no longer see flicker, hydration mismatches, or stale content across refreshes. Stored profile metadata is now validated and merged safely, recovering gracefully from malformed local data.
Test infrastructure (pre-existing failures):
vitest.config.ts: remove duplicate setupFiles key (empty array shadowed vitest.setup.ts) so jest-dom matchers load, fixing the SigningSummary failures.
usePersistentState.ts: hold serialize/deserialize in refs so inline (unstable) callback identities no longer re-trigger the hydration effect into an infinite re-render loop; fixed its test (jest -> vi, correct import path).
Metadata consistency:
types/profile.ts: add ProfileMetadata, PROFILE_METADATA_DEFAULTS, and sanitizeProfileMetadata (hex color, absolute http(s) avatar URL, trimmed + length-capped bio/handles; never throws).
lib/api.ts: readStoredProfileMetadata + safe merge with per-field sanitization; corrupt/non-object localStorage entries are removed on read; storage keys canonicalized to lowercase in getProfile/saveProfile.
app/[username]/page.tsx: reset state per username change, avatar onError fallback to initial, consistent error copy for invalid/private/not-found states, role=status + role=alert + aria-live.
Hydration-safe time/locale rendering:
hooks/marketplaceApi.ts: export standalone formatCountdown(date, now?) mirroring the provider implementations.
components/UsernameCard.tsx: mounted-pattern 'now' state (updated every 30s) replaces Date.now() at render to keep countdown/urgency/UrgencyBar identical between SSR and client.
lib/i18n.ts: init deterministically in 'en' on server and client; components/Header.tsx restores the saved language post-hydration and fixes the leading-space aria-label.
Other:
Pre-existing type/build errors fixed so the app compiles:
app/page.tsx: drop dead fetchListings warm-up (import never existed).
app/dashboard/page.tsx: consume fetchUserBids/fetchUserListings via MarketplaceApiProvider + useMarketplaceApi().
app/marketplace/page.tsx: remove duplicate showWatchlistOnly state and import useRef.
components/PWAHandler.tsx: pass route/extra context to errorReporter (valid ErrorContext).
Verification: full vitest suite green (12 files, 105 tests) and tsc --noEmit -p tsconfig.test.json clean. New unit tests cover sanitizeProfileMetadata and api.ts merge/recovery behavior.
Close #524