Skip to content

fix(frontend): eliminate profile hydration drift and harden stored me… - #529

Merged
MaryammAli merged 1 commit into
BlockDash-Studios:mainfrom
IamOluwatoyin:fix/profile-hydration-metadata
Aug 18, 2026
Merged

fix(frontend): eliminate profile hydration drift and harden stored me…#529
MaryammAli merged 1 commit into
BlockDash-Studios:mainfrom
IamOluwatoyin:fix/profile-hydration-metadata

Conversation

@IamOluwatoyin

Copy link
Copy Markdown
Contributor

…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.

Close #524

…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.

@MaryammAli MaryammAli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaryammAli
MaryammAli merged commit 49b6a62 into BlockDash-Studios:main Aug 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix public profile hydration and local metadata handling for user content

2 participants