Skip to content

Conversation

@LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Nov 25, 2025

Description

The environment resource is currently cached on the network level, therefore, when enabling orgs via BAPI, and coming back to the app, the session gets updated to have a session task but it could still have organizationSettings.enabled=false

This PR introduces an additional check to only trigger the prompt if there's not a choose-organization task

The choose-organization task only gets added once orgs are enabled

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
    • Fixed an issue where the enable-organization prompt could unexpectedly reappear when returning to complete a pending choose-organization task. After enabling organizations in the Dashboard, users will no longer see the prompt again for existing sessions with that pending task, resulting in a smoother organization onboarding and task-completion flow for affected users.

✏️ Tip: You can customize this high-level summary in your review settings.

@LauraBeatris LauraBeatris self-assigned this Nov 25, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2025

🦋 Changeset detected

Latest commit: 81c0597

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

@vercel
Copy link

vercel bot commented Nov 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Nov 25, 2025 2:16pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 25, 2025

Walkthrough

Prevents the "enable organization" prompt from appearing when a session has a pending choose-organization task by changing the organizations check in Clerk and adding a test plus a changelog entry documenting the patch.

Changes

Cohort / File(s) Summary
Changelog Entry
.changeset/afraid-women-buy.md
Adds a patch release note describing the fix for the enable-organization prompt reappearing due to cached environment resources.
Core Logic Fix
packages/clerk-js/src/core/clerk.ts
Adjusts __internal_attemptToEnableEnvironmentSetting so the organizations setting is treated as enabled when the current task is choose-organization, preventing the prompt in that scenario.
Test Coverage
packages/clerk-js/src/core/__tests__/clerk.test.ts
Adds a test ensuring the prompt is not shown when development is enabled and a session has a pending choose-organization task; adds afterEach cleanup for mock fetches.

Sequence Diagram

sequenceDiagram
    participant User
    participant ClerkApp as Clerk App
    participant Session
    participant EnvCheck as Org Feature Check

    rect rgb(230, 240, 250)
    Note over User,EnvCheck: Before fix — cached env causes prompt
    User->>ClerkApp: Redirect after enabling organizations
    ClerkApp->>Session: Load session (has choose-organization task)
    Session-->>ClerkApp: Return pending task
    ClerkApp->>EnvCheck: Check organizations setting
    EnvCheck-->>ClerkApp: Feature appears disabled → show prompt
    ClerkApp->>User: ❌ Enable organization prompt appears
    end

    rect rgb(240, 250, 240)
    Note over User,EnvCheck: After fix — prompt suppressed during task
    User->>ClerkApp: Redirect after enabling organizations
    ClerkApp->>Session: Load session (has choose-organization task)
    Session-->>ClerkApp: Return pending task
    ClerkApp->>EnvCheck: Check organizations setting
    EnvCheck->>EnvCheck: Is current task == "choose-organization"?
    EnvCheck-->>ClerkApp: Treat as enabled → suppress prompt
    ClerkApp->>User: ✓ Continue to choose-organization
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Areas to review closely:
    • The conditional change in __internal_attemptToEnableEnvironmentSetting for correct task detection and short-circuit behavior.
    • Test setup and mocks in clerk.test.ts to ensure they represent the session state and that mock fetch cleanup is adequate.
    • Ensure no other flows relying on the previous disabled-flag behavior are unintentionally changed.

Poem

🐰 A prompt that once chased users near and far,
Now pauses politely when tasks set the bar.
Cached envs may linger, but logic is kind,
Choose-organization proceeds—no prompt left behind. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: preventing the organizations prompt from appearing when a choose-organization task is pending, which directly corresponds to the core fix implemented in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch laura/fix-enable-orgs-with-task

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

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.

📥 Commits

Reviewing files that changed from the base of the PR and between b248601 and 81c0597.

📒 Files selected for processing (3)
  • .changeset/afraid-women-buy.md (1 hunks)
  • packages/clerk-js/src/core/__tests__/clerk.test.ts (2 hunks)
  • packages/clerk-js/src/core/clerk.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

All code must pass ESLint checks with the project's configuration

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Follow established naming conventions (PascalCase for components, camelCase for variables)

Prefer importing types from @clerk/shared/types instead of the deprecated @clerk/types alias

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
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/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
**/*.ts?(x)

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

Files:

  • packages/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
**/*.{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
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details in classes
Use protected for inheritance hierarchies
Use public explicitly 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 like Omit, Partial, and Pick for 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
Use const assertions with as const for literal types
Use satisfies operator 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/clerk-js/src/core/clerk.ts
  • packages/clerk-js/src/core/__tests__/clerk.test.ts
**/*.{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/clerk-js/src/core/__tests__/clerk.test.ts
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use real Clerk instances for integration tests

Files:

  • packages/clerk-js/src/core/__tests__/clerk.test.ts
🧬 Code graph analysis (2)
packages/clerk-js/src/core/clerk.ts (1)
packages/clerk-js/src/utils/componentGuards.ts (1)
  • disabledOrganizationsFeature (21-23)
packages/clerk-js/src/core/__tests__/clerk.test.ts (1)
packages/clerk-js/src/core/clerk.ts (1)
  • Clerk (204-3148)
⏰ 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). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (4)
packages/clerk-js/src/core/clerk.ts (1)

764-768: LGTM! Well-reasoned fix for the cached environment issue.

The additional check correctly prevents the enable-organizations prompt from appearing when a choose-organization task is present, even if organizationSettings.enabled is cached as false. The logic is sound: the presence of the task indicates that organizations have already been enabled server-side.

The use of optional chaining handles all edge cases gracefully (null session, null currentTask), and the inline comment clearly explains the caching scenario this addresses.

packages/clerk-js/src/core/__tests__/clerk.test.ts (2)

2513-2516: LGTM! Good test hygiene.

Adding the afterEach hook to reset mocks between tests is excellent practice and prevents test pollution that could cause flaky tests in the suite.


2639-2699: LGTM! Comprehensive test coverage for the edge case.

The test effectively covers the specific scenario described in the PR:

  • Mock session with choose-organization task in pending status
  • Organizations disabled in environment (simulating cached state)
  • Verifies that isEnabled returns true despite disabled state
  • Confirms the prompt is not opened

The test setup mirrors existing patterns in the file and includes a clear rationale comment explaining the caching scenario. The assertions validate both the positive case (isEnabled=true) and the negative case (prompt not called).

.changeset/afraid-women-buy.md (1)

1-7: LGTM! Clear and accurate changelog entry.

The changelog appropriately documents this as a patch fix and provides clear context about the issue (cached environment resources causing the prompt to reappear during the choose-organization task). The description will help users understand the fix when reviewing release notes.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 25, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 81c0597

@LauraBeatris LauraBeatris force-pushed the laura/fix-enable-orgs-with-task branch 2 times, most recently from 2f3d636 to 9419ce1 Compare November 25, 2025 14:12
@LauraBeatris LauraBeatris force-pushed the laura/fix-enable-orgs-with-task branch from 9419ce1 to 81c0597 Compare November 25, 2025 14:15
@LauraBeatris LauraBeatris enabled auto-merge (squash) November 25, 2025 15:26
@LauraBeatris LauraBeatris merged commit b0846e9 into main Nov 25, 2025
172 of 178 checks passed
@LauraBeatris LauraBeatris deleted the laura/fix-enable-orgs-with-task branch November 25, 2025 17:34
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