Skip to content

feat(sdk-react): ship ssr-safe hooks for next.js app router#162

Open
DSOTec wants to merge 1 commit into
wraith-protocol:developfrom
DSOTec:feat/130-sdk-react-ssr-safe-hooks
Open

feat(sdk-react): ship ssr-safe hooks for next.js app router#162
DSOTec wants to merge 1 commit into
wraith-protocol:developfrom
DSOTec:feat/130-sdk-react-ssr-safe-hooks

Conversation

@DSOTec

@DSOTec DSOTec commented Jul 25, 2026

Copy link
Copy Markdown

Summary

  • hooks.ts had no "use client" pragma, so any Next.js App Router Server Component tree that imported @wraith-protocol/sdk-react failed next build with "you're importing a component that needs useState." Added the pragma to the source and pinned it as a tsup banner so it survives bundling into both ESM and CJS dist/ output.
  • Added examples/stellar-nextjs-app-router/: a Server Component page renders a client-boundary component that calls the hooks, proving next build completes without SSR errors. Wired it into the Examples CI matrix.
  • Building against the real (non-mocked) SDK surfaced a second, adjacent bug: hooks.ts still called fetchAnnouncements, renamed to fetchAnnouncementsStream a while back. The package's env.d.ts shadowed the real SDK types with any-typed ambient declarations, hiding the drift from both tsc and the mocked hook tests. Updated the scan hook to consume the async generator and deleted env.d.ts so the package now type-checks against the SDK's real exports.

Testing

  • pnpm format:check, pnpm build, pnpm test (990 passed) at the repo root
  • next build on the new example — succeeds, statically prerenders /, no SSR errors
  • Confirmed "use client" is the first line of both packages/sdk-react/dist/index.js and dist/index.cjs
  • Confirmed existing Vite-based React examples (react-stellar-app, stellar-react-receive) still build

Closes #130

hooks.ts had no "use client" pragma, so any Next.js App Router Server
Component tree that reached it failed to build with "you're importing a
component that needs useState." Add the pragma to the source and pin it as
a tsup banner so it survives bundling into both the ESM and CJS dist output
regardless of esbuild's directive-hoisting behavior.

Add examples/stellar-nextjs-app-router to demonstrate the fix: a Server
Component page renders a client boundary component that calls the hooks,
and `next build` now completes without SSR errors.

Building the example against the real (non-mocked) package surfaced a
second bug: hooks.ts still called `fetchAnnouncements`, which was renamed
to `fetchAnnouncementsStream` a while back. The package's env.d.ts shadowed
the real SDK types with `any`-typed ambient declarations, so neither
tsc nor the mocked hook tests caught the drift. Update the scan hook to
consume the async generator and delete env.d.ts so the package type-checks
against the SDK's real exports going forward.

Closes wraith-protocol#130
@drips-wave

drips-wave Bot commented Jul 25, 2026

Copy link
Copy Markdown

@DSOTec 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

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.

sdk-react: SSR-safe hooks (Next.js App Router compat)

1 participant