Repository navigation
fix(auth-js): mark the react entry as a client component module - #2268
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 7f1fa22 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
@Taiwudao Thank you! |
Merged
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.
Summary
Mark
@hono/auth-js/reactas a Client Component module by adding the"use client"directive as the first statement ofpackages/auth-js/src/react.tsx.Problem
@hono/auth-js/reactis 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-levelReact.createContext()call runs there, and the request crashes with:Reproduced in #1103. This is the same problem NextAuth solved in its own react entry:
next-auth'sreact.tsxstarts 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.@hono/auth-js(patch).Verification
pnpm --filter @hono/auth-js test: 18 tests pass. The new test fails onmainand passes with the directive.pnpm --filter @hono/auth-js typecheck: passes.tsdownkeeps the directive in the published ESM entry:dist/react.mjsstarts with"use client";.