Skip to content

fix(auth-js): mark the react entry as a client component module - #2268

Merged
yusukebe merged 2 commits into
honojs:mainfrom
Taiwudao:fix/auth-js-use-client
Nov 22, 2026
Merged

yusukebe merged 2 commits into
honojs:mainfrom
Taiwudao:fix/auth-js-use-client

Conversation

@Taiwudao

Copy link
Copy Markdown
Contributor

Summary

Mark @hono/auth-js/react as a Client Component module by adding the "use client" directive as the first statement of packages/auth-js/src/react.tsx.

Problem

@hono/auth-js/react is a client-only entry. It creates a React context at module scope and every export (SessionProvider, useSession, signIn, signOut, ...) depends on React hooks, window, or browser APIs. When a React Server Component imports anything from the entry, Next.js evaluates the module in the server graph, the top-level React.createContext() call runs there, and the request crashes with:

TypeError: createContext only works in Client Components.

Reproduced in #1103. This is the same problem NextAuth solved in its own react entry: next-auth's react.tsx starts with the "use client" directive, so Next.js assigns the module to the client graph instead of evaluating it on the server. The directive is ignored by non-RSC tooling.

Changes

  • packages/auth-js/src/react.tsx: add "use client" as the first statement. It must stay before any import because React only honors the directive when it is the first statement of the module.
  • packages/auth-js/src/react.test.ts: guard that the entry keeps the directive as its first statement, so a later import added above it cannot silently reintroduce the crash.
  • A changeset for @hono/auth-js (patch).

Verification

  • pnpm --filter @hono/auth-js test: 18 tests pass. The new test fails on main and passes with the directive.
  • pnpm --filter @hono/auth-js typecheck: passes.
  • tsdown keeps the directive in the published ESM entry: dist/react.mjs starts with "use client";.

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f1fa22

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/auth-js Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.68%. Comparing base (6f11fdd) to head (7f1fa22).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2268      +/-   ##
==========================================
- Coverage   92.69%   92.68%   -0.02%     
==========================================
  Files         119      119              
  Lines        4367     4359       -8     
  Branches     1139     1137       -2     
==========================================
- Hits         4048     4040       -8     
  Misses        284      284              
  Partials       35       35              
Flag Coverage Δ
auth-js 64.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@yusukebe

Copy link
Copy Markdown
Member

@Taiwudao Thank you!

@yusukebe
yusukebe merged commit 8f7e385 into honojs:main Nov 22, 2026
98 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 22, 2026
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.

2 participants