Skip to content

fix(clerk-js): Do not display invitation if membership is active #6208

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

Conversation

LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Jun 27, 2025

Description

Once the after-auth navigation occurs, it invalidates the client cache, and therefore, AcceptedInvitationsProvider loses its state.

This PR updates the existing render condition of InvitationPreview to take in account the ID of the active organization vs the invitation org ID, and if those match, then don't render it on the organization switcher.

Also, it's not possible to invalidate organization resources before navigating away from the after-auth screen; otherwise, it'll result in a change of UI state.

With fix

CleanShot.2025-06-27.at.15.03.46.mp4

🐛

CleanShot.2025-06-27.at.15.05.41.mp4

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Bug Fixes
    • Improved the Organization Switcher to hide invitation options for users who are already active members of an organization, preventing redundant prompts.
    • Enhanced logic to ensure accepted invitations are hidden when the invitation's organization matches the active organization, providing a cleaner user experience.

@LauraBeatris LauraBeatris self-assigned this Jun 27, 2025
Copy link

changeset-bot bot commented Jun 27, 2025

🦋 Changeset detected

Latest commit: 0199b0c

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

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo 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

Copy link

vercel bot commented Jun 27, 2025

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

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 5:58pm

@LauraBeatris LauraBeatris marked this pull request as ready for review June 27, 2025 18:06
@LauraBeatris LauraBeatris requested a review from a team June 27, 2025 18:06
Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

📝 Walkthrough

Walkthrough

This change updates the @clerk/clerk-js package, specifically modifying the OrganizationSwitcher component and its related logic. The update ensures that the invitation option is hidden for users who are already active members of an organization, preventing redundant invitation prompts. In the UserInvitationSuggestionList.tsx file, the condition for hiding accepted invitations is expanded to also check if the invitation's public organization ID matches the active organization's ID, in addition to the previous check against the accepted organization's ID. No public or exported entity declarations were altered.


🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in 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.

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)
.changeset/yummy-laws-hunt.md (1)

5-5: Minor grammatical improvement suggested.

Consider adding the article "the" before "user" for better readability.

-Hide invitation in `OrganizationSwitcher` when user is already an active member of the organization
+Hide invitation in `OrganizationSwitcher` when the user is already an active member of the organization
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d898eb7 and 0199b0c.

📒 Files selected for processing (2)
  • .changeset/yummy-laws-hunt.md (1 hunks)
  • packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
`**/*.{js,ts,tsx,jsx}`: All code must pass ESLint checks with the project's configuration. Use Prettier for consistent code formatting.

**/*.{js,ts,tsx,jsx}: All code must pass ESLint checks with the project's configuration.
Use Prettier for consistent code formatting.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.tsx
`**/*.{ts,tsx}`: Maintain comprehensive JSDoc comments for public APIs.

**/*.{ts,tsx}: Maintain comprehensive JSDoc comments for public APIs.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.tsx
`packages/**`: All publishable packages under the @clerk namespace must be located in the packages/ directory.

packages/**: All publishable packages under the @clerk namespace must be located in the packages/ directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/global.mdc)

List of files the instruction was applied to:

  • packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.tsx
`**/*.{jsx,tsx}`: Always use functional components with hooks instead of class c...

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components.
Follow PascalCase naming for components; the filename and component name should match.
Limit component size to 150-200 lines; extract logic into custom hooks.
Export components as named exports for better tree-shaking.
One component per file with matching filename and component name.
Co-locate related files (component, test, stories) in the same directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/react.mdc)

List of files the instruction was applied to:

  • packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.tsx
🧠 Learnings (2)
📓 Common learnings
Learnt from: dstaley
PR: clerk/javascript#6116
File: .changeset/tangy-garlics-say.md:1-2
Timestamp: 2025-06-13T16:09:53.061Z
Learning: In the Clerk JavaScript repository, contributors create intentionally empty changeset files (containing only the YAML delimiters) when a PR touches only non-published parts of the codebase (e.g., sandbox assets). This signals that no package release is required, so such changesets should not be flagged as missing content.
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/index.tsx:64-83
Timestamp: 2025-06-18T16:33:36.764Z
Learning: In SessionTasks component at packages/clerk-js/src/ui/components/SessionTasks/index.tsx, the useEffect that checks for pending tasks should only run on mount (not react to currentTask/status changes) to handle browser back navigation edge cases without interfering with normal task completion flow managed by nextTask().
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/tasks/ForceOrganizationSelection.tsx:17-21
Timestamp: 2025-06-18T23:27:13.537Z
Learning: In Clerk's JavaScript codebase, query errors from hooks like useOrganizationList are not typically handled in AIO (All-in-One) components. Error handling may be connected with the Card context instead, suggesting a centralized error handling approach rather than component-level error handling.
.changeset/yummy-laws-hunt.md (3)
Learnt from: dstaley
PR: clerk/javascript#6116
File: .changeset/tangy-garlics-say.md:1-2
Timestamp: 2025-06-13T16:09:53.061Z
Learning: In the Clerk JavaScript repository, contributors create intentionally empty changeset files (containing only the YAML delimiters) when a PR touches only non-published parts of the codebase (e.g., sandbox assets). This signals that no package release is required, so such changesets should not be flagged as missing content.
Learnt from: jacekradko
PR: clerk/javascript#5905
File: .changeset/six-ears-wash.md:1-3
Timestamp: 2025-06-26T03:27:05.511Z
Learning: In the Clerk JavaScript repository, changeset headers support single quotes syntax (e.g., '@clerk/backend': minor) and work fine with their current changesets integration, so there's no need to change them to double quotes.
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/tasks/ForceOrganizationSelection.tsx:17-21
Timestamp: 2025-06-18T23:27:13.537Z
Learning: In Clerk's JavaScript codebase, query errors from hooks like useOrganizationList are not typically handled in AIO (All-in-One) components. Error handling may be connected with the Card context instead, suggesting a centralized error handling approach rather than component-level error handling.
🪛 LanguageTool
.changeset/yummy-laws-hunt.md

[uncategorized] ~5-~5: You might be missing the article “the” here.
Context: ...vitation in OrganizationSwitcher when user is already an active member of the orga...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

🔇 Additional comments (1)
packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.tsx (1)

171-174: LGTM! The expanded condition correctly addresses the cache invalidation issue.

The addition of the direct comparison between invitation.publicOrganizationData.id and activeOrganization?.id provides a reliable fallback when the AcceptedInvitationsProvider loses its state after cache invalidation. This ensures invitations are properly hidden when the user is already an active member of the organization.

Copy link

pkg-pr-new bot commented Jun 27, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6208

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6208

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6208

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6208

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6208

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6208

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6208

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6208

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6208

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6208

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6208

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6208

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6208

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6208

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6208

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6208

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6208

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6208

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6208

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6208

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6208

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6208

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6208

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6208

commit: 0199b0c

@LauraBeatris LauraBeatris merged commit 1e737c7 into main Jun 27, 2025
110 of 112 checks passed
@LauraBeatris LauraBeatris deleted the laura/orgs-722-invitation-still-gets-displayed-on-organization-switcher branch June 27, 2025 18:54
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.

4 participants