Skip to content

chore(clerk-js,ui): Add infinite loading to organization selection in OAuthConsent#8309

Merged
wobsoriano merged 13 commits intomainfrom
rob/org-select-infinite
Apr 16, 2026
Merged

chore(clerk-js,ui): Add infinite loading to organization selection in OAuthConsent#8309
wobsoriano merged 13 commits intomainfrom
rob/org-select-infinite

Conversation

@wobsoriano
Copy link
Copy Markdown
Member

@wobsoriano wobsoriano commented Apr 15, 2026

Description

Adds infinite loading to the organization selector inside OAuthConsent component.

Screen.Recording.2026-04-15.at.4.34.39.PM.mov

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:

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: ca85029

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

This PR includes changesets to release 2 packages
Name Type
@clerk/ui Patch
@clerk/chrome-extension 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
Copy Markdown

vercel bot commented Apr 15, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Apr 16, 2026 4:44pm

Request Review

- Add `OrgSelect` component with infinite scroll support using `useInView` + `InfiniteListSpinner`
- Pre-select the active org in the org picker dropdown
- Refactor `SelectOptionList` to accept a generic `footer` slot instead of `hasMore`/`onLoadMore` props, keeping pagination concerns out of the shared primitive
- Gate all org selection UI behind `ctx.enableOrgSelection` so the accounts portal path is unaffected
- Include synthetic org data for manual testing until a real 10+ org account is available
@wobsoriano wobsoriano marked this pull request as ready for review April 15, 2026 23:34
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Org selection gained infinite-scroll support: OrgSelect now accepts optional hasMore and onLoadMore, uses useInView to trigger onLoadMore when a sentinel becomes visible, and shows an InfiniteListSpinner footer when more items exist. SelectOptionList gained optional footer and onReachEnd props; keyboard ArrowDown invokes onReachEnd when focus is on the last option. OAuthConsent passes hasMore/onLoadMore into OrgSelect and removed an explicit pageSize. Tests add mocks for useInView and organization hooks to exercise the sentinel and selection fallback. A sandbox import reorder and a small formatting change were made.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding infinite loading to organization selection in OAuthConsent across clerk-js and ui packages.
Description check ✅ Passed The description is directly related to the changeset, explaining that infinite loading was added to the organization selector inside OAuthConsent.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ui/src/components/OAuthConsent/OAuthConsent.tsx (1)

37-40: ⚠️ Potential issue | 🔴 Critical

Remove synthetic org data from runtime org-selection flow.

Line 49 through Line 62 fabricates organizations and Line 251 through Line 252 wires load-more to syntheticFetchNext instead of the real memberships paginator. With org selection enabled, users can select synthetic IDs and submit invalid organization_id values, while real multi-page memberships are never fetched. This is a merge blocker.

Proposed fix
-  // TEMP: Synthetic orgs for manual infinite-scroll testing.
-  // Remove in follow-up once testing with a real account that has 10+ orgs.
-  const [syntheticPage, setSyntheticPage] = useState(1);
-  const syntheticOrgs: OrgOption[] = ctx.enableOrgSelection
-    ? Array.from({ length: syntheticPage * 5 }, (_, i) => ({
-        value: `synthetic_org_${i + 1}`,
-        label: `Synthetic Org ${i + 1}`,
-        logoUrl: orgOptions[0]?.logoUrl ?? '',
-      }))
-    : [];
-  const mergedOrgOptions = ctx.enableOrgSelection ? [...orgOptions, ...syntheticOrgs] : orgOptions;
-  const syntheticHasMore = ctx.enableOrgSelection && syntheticPage < 4; // 4 pages x 5 = 20 total
-  const syntheticFetchNext = () => setSyntheticPage(p => p + 1);
-  // TEMP END
+  const mergedOrgOptions = orgOptions;
+  const hasMoreMemberships = Boolean(ctx.enableOrgSelection && userMemberships.hasNextPage);
+  const loadMoreMemberships = () => {
+    if (!ctx.enableOrgSelection || userMemberships.isLoading || !userMemberships.hasNextPage) {
+      return;
+    }
+    void userMemberships.fetchNext?.();
+  };

@@
-                hasMore={syntheticHasMore}
-                onLoadMore={syntheticFetchNext}
+                hasMore={hasMoreMemberships}
+                onLoadMore={loadMoreMemberships}

Also applies to: 49-62, 251-252

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ui/src/components/OAuthConsent/OAuthConsent.tsx` around lines 37 -
40, The component is inserting synthetic organizations and wiring the load-more
button to syntheticFetchNext which allows selecting invalid organization_id
values; remove the synthetic org fabrication and instead use the real paginator
returned by useOrganizationList (the userMemberships result) and its
fetchNext/fetchMore method when ctx.enableOrgSelection is true; update the
load-more handler (replace syntheticFetchNext) to call the paginator from
useOrganizationList and ensure the selected organization IDs come from
userMemberships items so only real IDs are submitted.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/ui/src/components/OAuthConsent/OAuthConsent.tsx`:
- Around line 37-40: The component is inserting synthetic organizations and
wiring the load-more button to syntheticFetchNext which allows selecting invalid
organization_id values; remove the synthetic org fabrication and instead use the
real paginator returned by useOrganizationList (the userMemberships result) and
its fetchNext/fetchMore method when ctx.enableOrgSelection is true; update the
load-more handler (replace syntheticFetchNext) to call the paginator from
useOrganizationList and ensure the selected organization IDs come from
userMemberships items so only real IDs are submitted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 3d37727e-4008-43ba-891a-0a9ceff80768

📥 Commits

Reviewing files that changed from the base of the PR and between 45b773a and 1332fcc.

📒 Files selected for processing (5)
  • packages/clerk-js/sandbox/app.ts
  • packages/ui/src/components/OAuthConsent/OAuthConsent.tsx
  • packages/ui/src/components/OAuthConsent/OrgSelect.tsx
  • packages/ui/src/components/OAuthConsent/__tests__/OAuthConsent.test.tsx
  • packages/ui/src/elements/Select.tsx

);
})}
{noResultsMessage && options.length === 0 && <SelectNoResults>{noResultsMessage}</SelectNoResults>}
{footer}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's probably a better way there but simplest is just adding an element here to keep pagination concerns out of the shared primitive. The OrgSelect component owns the scroll detection logic and passes the spinner in as a footer when there are more pages to load

@wobsoriano wobsoriano closed this Apr 15, 2026
@wobsoriano wobsoriano reopened this Apr 15, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8309

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8309

@clerk/upgrade

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

@clerk/vue

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

commit: ca85029

Comment on lines +299 to +302
if (onReachEnd && focusedIndex === options.length - 1) {
onReachEnd();
return;
}
Copy link
Copy Markdown
Member Author

@wobsoriano wobsoriano Apr 16, 2026

Choose a reason for hiding this comment

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

should not break existing components interactions like the phone number input. Only invokes the method if it exists

@wobsoriano wobsoriano merged commit 6f36c51 into main Apr 16, 2026
42 checks passed
@wobsoriano wobsoriano deleted the rob/org-select-infinite branch April 16, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants