Skip to content

Commit 02798f5

Browse files
authored
fix(shared): Move organization environment helper to React-specific shared path (#7334)
1 parent eccc430 commit 02798f5

File tree

6 files changed

+36
-29
lines changed

6 files changed

+36
-29
lines changed

.changeset/proud-ads-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/shared": patch
3+
---
4+
5+
Moved helper to enable Organizations feature to React-specific shared path
Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { useEffect, useRef } from 'react';
2-
3-
import { useClerk } from './react';
41
import type { OrganizationMembershipResource } from './types';
52

63
/**
@@ -18,27 +15,3 @@ export function getCurrentOrganizationMembership(
1815
organizationMembership => organizationMembership.organization.id === organizationId,
1916
);
2017
}
21-
22-
/**
23-
* Attempts to enable the organizations environment setting for a given caller
24-
*
25-
* @internal
26-
*/
27-
export function useAttemptToEnableOrganizations(caller: 'useOrganization' | 'useOrganizationList') {
28-
const clerk = useClerk();
29-
const hasAttempted = useRef(false);
30-
31-
useEffect(() => {
32-
// Guard to not run this effect twice on Clerk resource update
33-
if (hasAttempted.current) {
34-
return;
35-
}
36-
37-
hasAttempted.current = true;
38-
// Optional chaining is important for `@clerk/clerk-react` usage with older clerk-js versions that don't have the method
39-
clerk.__internal_attemptToEnableEnvironmentSetting?.({
40-
for: 'organizations',
41-
caller,
42-
});
43-
}, [clerk, caller]);
44-
}

packages/shared/src/react/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export { assertContextExists, createContextAndHook } from './createContextAndHoo
22
export { useAPIKeys as __experimental_useAPIKeys } from './useAPIKeys';
33
export { useOrganization } from './useOrganization';
44
export { useOrganizationList } from './useOrganizationList';
5+
export { useAttemptToEnableOrganizations } from './useAttemptToEnableOrganizations';
56
export { useSafeLayoutEffect } from './useSafeLayoutEffect';
67
export { useSession } from './useSession';
78
export { useSessionList } from './useSessionList';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
import { useClerk } from './useClerk';
4+
5+
/**
6+
* Attempts to enable the organizations environment setting for a given caller
7+
*
8+
* @internal
9+
*/
10+
export function useAttemptToEnableOrganizations(caller: 'useOrganization' | 'useOrganizationList') {
11+
const clerk = useClerk();
12+
const hasAttempted = useRef(false);
13+
14+
useEffect(() => {
15+
// Guard to not run this effect twice on Clerk resource update
16+
if (hasAttempted.current) {
17+
return;
18+
}
19+
20+
hasAttempted.current = true;
21+
// Optional chaining is important for `@clerk/clerk-react` usage with older clerk-js versions that don't have the method
22+
clerk.__internal_attemptToEnableEnvironmentSetting?.({
23+
for: 'organizations',
24+
caller,
25+
});
26+
}, [clerk, caller]);
27+
}

packages/shared/src/react/hooks/useOrganization.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentOrganizationMembership, useAttemptToEnableOrganizations } from '../../organization';
1+
import { getCurrentOrganizationMembership } from '../../organization';
22
import { eventMethodCalled } from '../../telemetry/events/method-called';
33
import type {
44
GetDomainsParams,
@@ -20,6 +20,7 @@ import {
2020
import { STABLE_KEYS } from '../stable-keys';
2121
import type { PaginatedHookConfig, PaginatedResources, PaginatedResourcesWithDefault } from '../types';
2222
import { createCacheKeys } from './createCacheKeys';
23+
import { useAttemptToEnableOrganizations } from './useAttemptToEnableOrganizations';
2324
import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';
2425

2526
/**

packages/shared/src/react/hooks/useOrganizationList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useAttemptToEnableOrganizations } from '../../organization';
21
import { eventMethodCalled } from '../../telemetry/events/method-called';
32
import type {
43
CreateOrganizationParams,
@@ -15,6 +14,7 @@ import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useUserContex
1514
import { STABLE_KEYS } from '../stable-keys';
1615
import type { PaginatedHookConfig, PaginatedResources, PaginatedResourcesWithDefault } from '../types';
1716
import { createCacheKeys } from './createCacheKeys';
17+
import { useAttemptToEnableOrganizations } from './useAttemptToEnableOrganizations';
1818
import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';
1919

2020
/**

0 commit comments

Comments
 (0)