Skip to content

fix: hydration error and button disabled state#3019

Closed
revogabe wants to merge 2 commits intounkeyed:mainfrom
revogabe:oauth-disabled-and-hydration
Closed

fix: hydration error and button disabled state#3019
revogabe wants to merge 2 commits intounkeyed:mainfrom
revogabe:oauth-disabled-and-hydration

Conversation

@revogabe
Copy link
Contributor

@revogabe revogabe commented Mar 21, 2025

What does this PR do?

Description

This PR fixes a hydration error on the auth page and also adds a disabled state to the OAuthButton.

Changes

  • Hydration Error
    Using a hook to check if it's on the client side and allowing Last Used to render only when on the client to prevent a hydration error.

  • Disabled State
    I added a disabled state to disable the button while making the request to Clerk. This will prevent glitches and improve the UX. I also adjusted the typing to accept props like a button without adding extra props manually.

Fixes #3018

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  1. Hydration Bug
    • Make sure bugs are no longer being popped on screen.

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features
    • Updated authentication buttons now display a disabled state with enhanced styling, providing clear visual feedback during sign-in.
    • Improved sign-in behavior by conditionally showing additional sign-in details and preventing duplicate submissions during processing.

@changeset-bot
Copy link

changeset-bot bot commented Mar 21, 2025

⚠️ No Changeset found

Latest commit: d9b8014

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 9:51pm

@vercel
Copy link

vercel bot commented Mar 21, 2025

@revogabe is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

📝 Walkthrough

Walkthrough

This pull request updates the OAuth components used for user authentication. The OAuthButton component now utilizes generic button element props (ButtonElementProps), allowing it to accept all standard button attributes including a new disabled prop with corresponding styling. In the OAuthSignIn component, a client-side check using the useIsClient hook has been added to conditionally render the LastUsed component. Additionally, the OAuth buttons are now disabled during loading, which helps prevent multiple sign-in attempts and addresses hydration errors.

Changes

File(s) Change Summary
apps/.../auth/oauth-button.tsx Replaced custom Props type with generic ButtonElementProps to accept all standard button attributes and added disabled state styling.
apps/.../auth/sign-in/oauth-signin.tsx Added the useIsClient hook to check for client-side rendering; conditionally renders the LastUsed component; passes disabled prop to OAuthButton based on loading.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant S as OAuthSignIn
    participant U as useIsClient Hook
    participant LB as LastUsed Component
    participant OB as OAuthButton

    C->>S: Request Sign In Page
    S->>U: Check if running on the client
    U-->>S: Return isClient (true/false)
    alt isClient is true
        S->>LB: Render LastUsed (GitHub, Google)
    else isClient is false
        S-xLB: Skip rendering LastUsed
    end
    S->>OB: Render OAuthButton (apply disabled state if loading)
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent hydration error on Auth Page (#3018)

Possibly related PRs

Suggested labels

Bug, Feature, Needs Approval

Suggested reviewers

  • mcstepp
  • chronark
  • perkinsjr
  • ogzhanolguncu
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 21, 2025

Thank you for following the naming conventions for pull request titles! 🙏

@github-actions github-actions bot added Bug Something isn't working Needs Approval Needs approval from Unkey labels Mar 21, 2025
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: 0

🧹 Nitpick comments (1)
apps/dashboard/app/auth/oauth-button.tsx (1)

7-16: Consider using rest props for additional button attributes

While the current implementation works well, you could make the component even more flexible by using the rest pattern to forward additional props to the button element.

-export const OAuthButton: React.FC<ButtonElementProps> = ({ onClick, disabled, children }) => {
+export const OAuthButton: React.FC<ButtonElementProps> = ({ onClick, disabled, children, ...rest }) => {
  return (
    <button
      type="button"
      disabled={disabled}
      className="relative flex items-center justify-center h-10 gap-2 px-4 text-sm font-semibold text-white duration-500 border rounded-lg bg-white/10 enabled:hover:bg-white enabled:hover:text-black border-white/10 disabled:opacity-50 disabled:cursor-not-allowed"
      onClick={onClick}
+      {...rest}
    >
      {children}
    </button>
  );
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 97703d2 and d9b8014.

📒 Files selected for processing (2)
  • apps/dashboard/app/auth/oauth-button.tsx (1 hunks)
  • apps/dashboard/app/auth/sign-in/oauth-signin.tsx (2 hunks)
🔇 Additional comments (11)
apps/dashboard/app/auth/sign-in/oauth-signin.tsx (6)

8-8: Good addition of useIsClient hook

Adding the useIsClient hook is an excellent way to handle rendering differences between server and client, which directly addresses the hydration issues mentioned in the PR objectives.


13-13: Well-implemented client-side detection

Using the useIsClient hook to create a boolean flag that determines client-side rendering is a clean approach to solving hydration issues.


40-43: Good implementation of disabled state

Adding the disabled property when the GitHub authentication is in progress prevents multiple submissions and improves user experience, which aligns well with the PR objectives.


49-49: Proper fix for hydration error

Conditionally rendering the LastUsed component only on the client side effectively prevents hydration mismatches between server and client rendering.


51-54: Consistent implementation for Google OAuth

The disabled state is correctly implemented for the Google OAuth button, maintaining consistency with the GitHub button implementation.


60-60: Proper conditional rendering for LastUsed

Consistent with the GitHub implementation, the LastUsed component for Google is also only rendered on the client side, preventing hydration issues.

apps/dashboard/app/auth/oauth-button.tsx (5)

3-3: Good type import for better component typing

Using ComponentProps from React is a good practice for creating type-safe components that properly extend HTML element props.


5-5: Well-defined button props type

Creating a type that extends all standard button properties allows the component to accept any valid button attribute without requiring additional prop definitions.


7-7: Improved component signature

Updating the component to use ButtonElementProps makes it more flexible and aligned with standard HTML button behavior, allowing it to accept all standard button attributes including the disabled state.


11-11: Properly implemented disabled state

Correctly forwarding the disabled prop to the native button element enables the functionality required by the PR objectives.


12-12: Well-crafted disabled styling

The className now properly handles the disabled state with appropriate visual feedback (opacity reduction and not-allowed cursor), and correctly uses the enabled: prefix for hover states to ensure they only apply when the button is active.

@perkinsjr
Copy link
Member

I am going to reject this request. For two reasons:

  1. We are in the middle of a migration to another provider and these pages are being attended too.
  2. Unless the Issue has been "Approved" to be worked on by a core team member please don't open a PR.

This is because we need to make sure it won't collide or be immediately obsolete with anything that we are working on.

@perkinsjr perkinsjr closed this Mar 21, 2025
@revogabe revogabe deleted the oauth-disabled-and-hydration branch March 21, 2025 21:55
@revogabe
Copy link
Contributor Author

i'm so sorry @perkinsjr

@perkinsjr
Copy link
Member

i'm so sorry @perkinsjr

All good 🫡 I just don't want you wasting your engineering efforts and finding out that we are working on it, or similarly we have plans to change everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Needs Approval Needs approval from Unkey

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Hydration Bug on Auth Page

2 participants