[PR #7763] [MERGED] fix(nextjs): detect RSC context to prevent unnecessary session refresh #24439

Closed
opened 2026-04-15 22:22:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7763
Author: @bytaesu
Created: 2/2/2026
Status: Merged
Merged: 2/2/2026
Merged by: @himself65

Base: canaryHead: 2026-02-03/next-rsc-session-refresh


📝 Commits (1)

  • f18c364 fix(nextjs): detect RSC context to prevent unnecessary session refresh

📊 Changes

2 files changed (+22 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session.ts (+3 -1)
📝 packages/better-auth/src/integrations/next-js.ts (+19 -7)

📄 Description

Note

References:
https://github.com/vercel/next.js/issues/65787#issuecomment-2701037353
https://nextjs.org/docs/app/api-reference/functions/cookies#good-to-know

The changes in PR #7625 were incomplete because RSC headers are inaccessible. I've updated it to detect RSC by using the constraints of cookies.set() in reverse.


Summary by cubic

Detects Server Component context in Next.js by probing cookie mutability and skips session refresh when cookies can’t be set. This prevents unnecessary refreshes and avoids DB/cookie mismatches in RSC requests. Closes #7394.

  • Bug Fixes
    • Added /get-session middleware that attempts cookies().set; on failure, flags shouldSkipSessionRefresh for RSC requests.
    • Updated getSession route to honor shouldSkipSessionRefresh before refreshing sessions near expiry.

Written for commit f18c36435d. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7763 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 2/2/2026 **Status:** ✅ Merged **Merged:** 2/2/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-02-03/next-rsc-session-refresh` --- ### 📝 Commits (1) - [`f18c364`](https://github.com/better-auth/better-auth/commit/f18c36435d638e92a7291c8826847d1a927da6b5) fix(nextjs): detect RSC context to prevent unnecessary session refresh ### 📊 Changes **2 files changed** (+22 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session.ts` (+3 -1) 📝 `packages/better-auth/src/integrations/next-js.ts` (+19 -7) </details> ### 📄 Description > [!NOTE] > References: > https://github.com/vercel/next.js/issues/65787#issuecomment-2701037353 > https://nextjs.org/docs/app/api-reference/functions/cookies#good-to-know The changes in PR #7625 were incomplete because RSC headers are inaccessible. I've updated it to detect RSC by using the constraints of `cookies.set()` in reverse. - Closes #7394 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Detects Server Component context in Next.js by probing cookie mutability and skips session refresh when cookies can’t be set. This prevents unnecessary refreshes and avoids DB/cookie mismatches in RSC requests. Closes #7394. - **Bug Fixes** - Added /get-session middleware that attempts cookies().set; on failure, flags shouldSkipSessionRefresh for RSC requests. - Updated getSession route to honor shouldSkipSessionRefresh before refreshing sessions near expiry. <sup>Written for commit f18c36435d638e92a7291c8826847d1a927da6b5. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:22:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#24439