Skip to content

fix(hooks): guard freighter API behind window check for SSR (#010)#71

Merged
ezedike-evan merged 2 commits intoezedike-evan:mainfrom
Clement-coder:fix/010-freighter-ssr-guard
Apr 27, 2026
Merged

fix(hooks): guard freighter API behind window check for SSR (#010)#71
ezedike-evan merged 2 commits intoezedike-evan:mainfrom
Clement-coder:fix/010-freighter-ssr-guard

Conversation

@Clement-coder
Copy link
Copy Markdown
Contributor

@Clement-coder Clement-coder commented Apr 24, 2026

Summary

/offramp was crashing on SSR because useFreighter called into the Freighter
browser extension before window existed. Guarding getFreighterApi() behind
typeof window !== 'undefined' makes the hook return a stable
{ isConnected: false, publicKey: null } during static render, eliminating the
crash and the hydration diff.

Linked issue

Closes #10

Changes

  • hooks/useFreighter.ts — getFreighterApi() throws early when
    typeof window === 'undefined'; the checkInstalled effect catches it and stays at
    INITIAL_STATE, giving zero hydration diff

Testing notes

Automated

  • npm run typecheck · ⏳ not run / ✅ green / ❌ failing
  • npm run lint · ⏳ not run / ✅ green / ❌ failing
  • npm run test · ⏳ not run / ✅ green / ❌ failing
  • npm run build · ⏳ not run / ✅ green / ❌ failing

New / modified tests

  • N/A — one-line SSR guard; no client behaviour changed

Manual verification

  • N/A — change only affects the server-render path; no Freighter interaction
    involved

Screenshots / recordings

N/A — no user-visible change; fixes a server-side crash.

Checklist

Correctness

  • The PR title follows Conventional Commits (auto-linted)
  • One logical change; unrelated cleanup was split into a separate PR
  • npm run typecheck passes
  • npm run lint passes with zero new warnings
  • npm run test passes; new behaviour has a test
  • npm run build passes

Data integrity

  • No fabricated rates, stub prices, or placeholder exchange rates
  • No isMock, // MOCK, // TODO: replace with real data, or commented-out real
    code
  • Not touching an anchor, SEP-10, SEP-24, or the status poll

Security & non-custody

  • No new code path holds user keys, user funds, or long-lived anchor JWTs
  • Every signing action is performed by the user's wallet (Freighter today)
  • No secrets committed; .env.local is unchanged; no new env vars

Docs

  • No user-facing behaviour change — no CHANGELOG.md entry needed
  • No API / schema / architecture change
  • No new env var

Release hygiene

  • No wave deliverable touched
  • No dependency added
  • No breaking change

Breaking changes

None.

For reviewers

Single-line fix. Guarding at getFreighterApi() covers both the mount effect and
the connect callback in one place, rather than duplicating the check in each
useEffect

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

@Clement-coder is attempting to deploy a commit to the ezedikeevan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 24, 2026

@Clement-coder Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@ezedike-evan ezedike-evan merged commit 0aad885 into ezedike-evan:main Apr 27, 2026
1 check failed
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.

[#010] page crashes when Freighter is undefined on first render

2 participants