Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix static generation issue #262

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

yyaskriloff
Copy link
Contributor

addressing issue #261

I had a hard time building the playground so I couldn't test building. also if it's not obvious this would be a breaking change because every call of getKindeServerSession would need to be switched to await

I chose headers but it can be accomplished with multiple different functions for more info https://nextjs.org/docs/app/building-your-application/rendering/server-components#dynamic-apis

🛟 If you need help, consider asking for advice over in the Kinde community.

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request modifies the src/session/index.ts file by converting the default export function from synchronous to asynchronous. The primary change involves adding the async keyword to the function signature and introducing an await for the connection() call. This modification enables the function to handle asynchronous operations more effectively, specifically waiting for the connection to resolve before proceeding with subsequent operations.

Changes

File Change Summary
src/session/index.ts - Updated function signature from synchronous to asynchronous by adding async keyword
- Added await connection() at the beginning of the function

Sequence Diagram

sequenceDiagram
    participant Func as Session Function
    participant Conn as Connection
    Func->>Conn: await connection()
    Conn-->>Func: Connection resolved
    Func->>Func: Continue with session operations
Loading

Possibly related PRs

Suggested reviewers

  • DanielRivers
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@yyaskriloff
Copy link
Contributor Author

I changed from using headers to the connection function. i saw that noStore was legacy but missed to use connection instead

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/session/index.ts (2)

Line range hint 28-33: Document RSC limitations in API documentation

The code comment about React Server Components (RSC) limitations with refreshTokens provides valuable information. Consider documenting this limitation in the package's API documentation to help users avoid potential issues.

Let's check if this limitation is already documented:

#!/bin/bash
# Search for existing documentation about RSC limitations
rg -g "*.md" -g "*.mdx" "React Server Components.*refreshTokens|RSC.*refreshTokens"

23-24: Consider alternative approaches to static generation

While using connection() from next/server might work, consider documenting why this approach was chosen over other alternatives mentioned in the PR description. This would help maintainers understand the trade-offs made.

Additionally, since this is a breaking change, consider:

  1. Adding migration guides in the documentation
  2. Updating the version number according to semver
  3. Adding deprecation warnings for the current synchronous usage
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91550c5 and 235963c.

📒 Files selected for processing (1)
  • src/session/index.ts (2 hunks)
🔇 Additional comments (1)
src/session/index.ts (1)

21-21: Breaking Change: Function signature updated to async

This change will require all instances of getKindeServerSession to be called with await. While this aligns with the PR objective to fix static generation, we should verify if this is the recommended approach.

Let's check for any existing usage patterns in the codebase:

Also applies to: 23-23

✅ Verification successful

Breaking change is intentional and aligned with existing patterns

The change to make getKindeServerSession async is:

  • Already anticipated in the codebase comments
  • Partially implemented in some routes (e.g., api/protected/route.ts)
  • Required for proper static generation as per PR objectives

Locations requiring updates:

  • playground/src/app/layout.tsx: Update to use await with getKindeServerSession()
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing getKindeServerSession usage patterns
rg "getKindeServerSession" -A 2

Length of output: 1700

src/session/index.ts Show resolved Hide resolved
@Yoshify
Copy link
Collaborator

Yoshify commented Jan 22, 2025

Nitpick but I think adding a comment in the code as to why we're doing this would be valuable here.

Making getKindeServerSession asynchronous is a big item on my radar at the moment as it would resolve a lot of problems (like this), but it's a breaking change - there's a lot of moving parts on the back end of things currently. A comment that points to why we're doing this (so that we can potentially remove this in future once we rewrite getKindeServerSession as asynchronous) would be great! 😄

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/session/index.ts (1)

24-25: Enhance the comment to explain the rationale.

While the comment explains what the code does, it would be helpful to add:

  1. Why connection() was chosen over other approaches
  2. The implications of this change on the build process
  3. Any potential future plans to remove this once getKindeServerSession is fully rewritten as async

Consider expanding the comment like this:

-  // This will prevent NextJS generating a static page where this function is called if no other Dynamic APIs are used.
+  // Using connection() to prevent NextJS from generating a static page where this function is called.
+  // This approach was chosen over alternatives because:
+  // 1. It's a documented Next.js API
+  // 2. It ensures consistent behavior across different Next.js versions
+  // Note: This might be removable once getKindeServerSession is fully rewritten as async
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 235963c and 30a2e33.

📒 Files selected for processing (1)
  • src/session/index.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/session/index.ts (1)
Learnt from: yyaskriloff
PR: kinde-oss/kinde-auth-nextjs#262
File: src/session/index.ts:24-24
Timestamp: 2025-01-22T13:04:16.055Z
Learning: The `connection()` function from 'next/server' is a documented Next.js API (https://nextjs.org/docs/app/api-reference/functions/connection) that can be used to detect when a connection with a client is lost/closed in Next.js applications.
🔇 Additional comments (2)
src/session/index.ts (2)

21-21: LGTM!

The import of connection from 'next/server' is correctly added and is necessary for preventing static page generation.


34-34: LGTM!

The addition of await for the sessionManager call is consistent with the async function signature change.


export default function (req?: NextApiRequest, res?: NextApiResponse) {
export default async function (req?: NextApiRequest, res?: NextApiResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Document the breaking change in function signature

The conversion of getKindeServerSession to async is a breaking change that requires all calls to be updated with await. While the playground examples demonstrate the correct usage, this breaking change should be explicitly documented in the CHANGELOG.md to help users understand the required migration steps.

Locations needing attention:

  • CHANGELOG.md: Add entry under v2.4.2 to document the breaking change in getKindeServerSession
  • Consider adding a migration guide to help users update their code
🔗 Analysis chain

Document the breaking change in function signature.

Converting this function to async is a breaking change that requires all getKindeServerSession calls to be updated with await. This should be documented in the changelog and migration guide.

Let's verify the impact of this breaking change:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing getKindeServerSession usage that might need updates
rg "getKindeServerSession" --type ts

Length of output: 711


Script:

#!/bin/bash
# Check the content of files using getKindeServerSession
echo "=== playground/src/app/layout.tsx ==="
cat playground/src/app/layout.tsx

echo -e "\n=== playground/src/app/api/protected/route.ts ==="
cat playground/src/app/api/protected/route.ts

Length of output: 3300


Script:

#!/bin/bash
# Check for changelog or migration guide
echo "=== Checking for CHANGELOG.md ==="
fd "CHANGELOG.md"

echo -e "\n=== Checking for migration guide ==="
fd -i "migration" -e md

Length of output: 220


Script:

#!/bin/bash
# Check CHANGELOG.md content
cat CHANGELOG.md

Length of output: 65555

@DanielRivers DanielRivers added this to the 3.x milestone Jan 23, 2025
@DanielRivers DanielRivers linked an issue Jan 23, 2025 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: using getKindeServerSession doesn't trigger ssr on demand
3 participants