Skip to content

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

Open
wobsoriano wants to merge 7 commits intomainfrom
rob/org-select-infinite
Open

chore(clerk-js,ui): Add infinite loading to organization selection in OAuthConsent#8309
wobsoriano wants to merge 7 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

⚠️ No Changeset found

Latest commit: 4ff149c

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
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 1:25am

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: 0a87c2ff-9718-45ee-98dd-f292623b7917

📥 Commits

Reviewing files that changed from the base of the PR and between 4852c74 and 4ff149c.

📒 Files selected for processing (1)
  • packages/ui/src/components/OAuthConsent/__tests__/OAuthConsent.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui/src/components/OAuthConsent/tests/OAuthConsent.test.tsx

📝 Walkthrough

Walkthrough

Org selection components gained infinite-scroll support: OrgSelect accepts optional hasMore and onLoadMore, uses a visibility sentinel via useInView to trigger loading, and renders a footer with a spinner when more items exist. SelectOptionList now accepts an optional footer and an onReachEnd callback used when keyboard navigation reaches the list end. OAuthConsent wires pagination controls (hasMore/onLoadMore) into OrgSelect and removes an explicit page size. Tests add mocks for useInView, expand organization-related mocks, and verify sentinel wiring and selection fallback. A minor import reorder and formatting tweak occurred in the sandbox app.

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 functionality to the organization selection component in OAuthConsent, which is directly reflected across multiple modified files.
Description check ✅ Passed The description clearly states the feature being added (infinite loading to the organization selector) and relates directly to the changeset modifications across clerk-js and ui packages.

✏️ 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: 4ff149c

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.

1 participant