-
Notifications
You must be signed in to change notification settings - Fork 422
fix(ui): Hide "must belong to org" screen when org resources exist #7553
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(ui): Hide "must belong to org" screen when org resources exist #7553
Conversation
🦋 Changeset detectedLatest commit: 0bb2879 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
94208f3 to
1206400
Compare
1206400 to
ca339e6
Compare
📝 WalkthroughWalkthroughA changeset was added for a patch release to the UI package updating the "You must belong to an organization" text. Tests were added for TaskChooseOrganization covering users with existing memberships or suggestions, and a test helper 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (13)**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.ts?(x)📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.tsx📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{md,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*⚙️ CodeRabbit configuration file
Files:
🧬 Code graph analysis (1)packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
Comment |
There was a problem hiding this 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
🤖 Fix all issues with AI agents
In
@packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx:
- Around line 303-310: The test uses withForceOrganizationSelection() but fails
to add the choose-organization task to the user fixture, so the component's
withTaskGuard prevents rendering; update the user fixture in this test (the
createFixtures callback that calls f.withUser(...)) to include tasks: [{ key:
'choose-organization' }], mirroring the other test, so the
TaskChooseOrganization component can render and the assertions at the end of the
test will run.
📜 Review details
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.changeset/tasty-animals-grab.mdpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsx
🧰 Additional context used
📓 Path-based instructions (18)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
packages/**/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components
**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{md,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Update documentation for API changes
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g.,UserProfile,NavigationMenu)
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use ESLint with custom configurations tailored for different package types
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use Prettier for code formatting across all packages
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*
⚙️ CodeRabbit configuration file
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
**/*: Only comment on issues that would block merging, ignore minor or stylistic concerns.
Restrict feedback to errors, security risks, or functionality-breaking problems.
Do not post comments on code style, formatting, or non-critical improvements.
Keep reviews short: flag only issues that make the PR unsafe to merge.
Group similar issues into a single comment instead of posting multiple notes.
Skip repetition: if a pattern repeats, mention it once at a summary level only.
Do not add general suggestions, focus strictly on merge-blocking concerns.
If there are no critical problems, respond with minimal approval (e.g., 'Looks good'). Do not add additional review.
Avoid line-by-line commentary unless it highlights a critical bug or security hole.
Highlight only issues that could cause runtime errors, data loss, or severe maintainability issues.
Ignore minor optimization opportunities, focus solely on correctness and safety.
Provide a top-level summary of critical blockers rather than detailed per-line notes.
Comment only when the issue must be resolved before merge, otherwise remain silent.
When in doubt, err on the side of fewer comments, brevity and blocking issues only.
Avoid posting any refactoring issues.
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/index.tsxpackages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use real Clerk instances for integration tests
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.test.tsx
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use React Testing Library for component testing
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.{test,spec}.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{test,spec}.{jsx,tsx}: Use React Testing Library for unit testing React components
Test component behavior, not implementation details
Use proper test queries in React Testing Library tests
Implement proper test isolation in React component tests
Use proper test coverage in React component tests
Test component interactions in integration tests
Use proper test data in React component tests
Implement proper test setup in React component tests
Use proper test cleanup in React component tests
Implement proper test assertions in React component tests
Use proper test structure for React component tests
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Use React Testing Library for component testing
Files:
packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
| it('with existing memberships or suggestions, displays create organization screen', async () => { | ||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withOrganizations(); | ||
| f.withForceOrganizationSelection(); | ||
| f.withUser({ | ||
| create_organization_enabled: false, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the test file to see the actual code around the flagged lines
head -320 packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx | tail -70Repository: clerk/javascript
Length of output: 2669
🏁 Script executed:
# Search for withForceOrganizationSelection implementation in fixtures
fd -e ts -e tsx | xargs rg -l "withForceOrganizationSelection" | head -5Repository: clerk/javascript
Length of output: 521
🏁 Script executed:
# Look at similar tests to compare task configuration
rg -n "withForceOrganizationSelection" packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx -B5 -A15Repository: clerk/javascript
Length of output: 9572
🏁 Script executed:
# Search for the withForceOrganizationSelection implementation
rg -n "withForceOrganizationSelection\s*\(" packages/clerk-js/src/test/fixture-helpers.ts -A 20Repository: clerk/javascript
Length of output: 42
🏁 Script executed:
# Also check if there's any task assignment related to organization selection in fixtures
rg -n "choose-organization" packages/clerk-js/src/test/fixture-helpers.ts -B 2 -A 2Repository: clerk/javascript
Length of output: 42
🏁 Script executed:
# Let's find and examine the fixture-helpers file
find . -name "fixture-helpers.ts" -o -name "fixture*.ts" | head -10Repository: clerk/javascript
Length of output: 148
🏁 Script executed:
# Search more broadly for withForceOrganizationSelection
rg "withForceOrganizationSelection" -A 15 -B 2Repository: clerk/javascript
Length of output: 40420
🏁 Script executed:
# Let's examine the withForceOrganizationSelection implementation and surrounding context
cat -n packages/clerk-js/src/test/fixture-helpers.ts | grep -A 5 -B 5 "withForceOrganizationSelection"Repository: clerk/javascript
Length of output: 782
🏁 Script executed:
# Let's also check the component to understand the task guard requirement
rg -n "withTaskGuard" packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/ -A 2 -B 2Repository: clerk/javascript
Length of output: 1237
🏁 Script executed:
# Let's find the withTaskGuard implementation in the shared file
rg -n "withTaskGuard" packages/ui/src/components/SessionTasks/tasks/shared -A 10 -B 2Repository: clerk/javascript
Length of output: 2046
🏁 Script executed:
# Let's also check the test that was shown to not render without the task
sed -n '16,31p' packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsxRepository: clerk/javascript
Length of output: 737
🏁 Script executed:
# Let's examine the full withRedirect logic to understand what happens when task is missing
rg -n "withRedirect" packages/ui/src/components/SessionTasks/tasks/shared/withTaskGuard.ts -B 2 -A 10Repository: clerk/javascript
Length of output: 1076
🏁 Script executed:
# Let's look at what the test expects to render at lines 349-351
sed -n '303,360p' packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsxRepository: clerk/javascript
Length of output: 1714
Add tasks array to the user fixture in this test.
The withForceOrganizationSelection() method only sets a configuration flag and does not automatically add the choose-organization task to the user. The component uses withTaskGuard (line 146 of index.tsx) which requires the task to be present in the session to render—without it, the component will redirect instead.
The test on lines 16-31 explicitly demonstrates this requirement by verifying the component does not render when the task is absent. The similar test on lines 286-301 (with the same configuration) includes tasks: [{ key: 'choose-organization' }]. Add this to the user fixture at lines 307-309 to ensure the component can render for the test assertions at lines 349-351 to execute.
🤖 Prompt for AI Agents
In
@packages/ui/src/components/SessionTasks/tasks/TaskChooseOrganization/__tests__/TaskChooseOrganization.test.tsx
around lines 303 - 310, The test uses withForceOrganizationSelection() but fails
to add the choose-organization task to the user fixture, so the component's
withTaskGuard prevents rendering; update the user fixture in this test (the
createFixtures callback that calls f.withUser(...)) to include tasks: [{ key:
'choose-organization' }], mirroring the other test, so the
TaskChooseOrganization component can render and the assertions at the end of the
test will run.
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
NicolasLopes7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me 👍
| const { otherSessions } = useMultipleSessions({ user }); | ||
| const { navigateAfterSignOut, navigateAfterMultiSessionSingleSignOutUrl } = useSignOutContext(); | ||
|
|
||
| const handleSignOut = () => { | ||
| if (otherSessions.length === 0) { | ||
| return signOut(navigateAfterSignOut); | ||
| } | ||
|
|
||
| return signOut(navigateAfterMultiSessionSingleSignOutUrl, { sessionId: session?.id }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was unused, somehow linter didn't caught it as well
ca339e6 to
0bb2879
Compare
Description
This PR fixes an issue where the "You must belong to an organization" was still being shown, even when the user had existing org memberships or suggestions to be chosen.
The previous implementation added a guard to check for the environment setting and display this screen, in order to avoid the loading status of the memberships/suggestions query, however this introduced the above bug.
🐛
Screen.Cast.2026-01-07.at.11.03.39.AM.mp4
With fix
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.