@sanity/sdk-react 2.8.0 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -63
- package/dist/index.d.ts +381 -571
- package/dist/index.js +435 -366
- package/dist/index.js.map +1 -1
- package/package.json +7 -9
- package/src/_exports/index.ts +4 -0
- package/src/_exports/sdk-react.ts +16 -0
- package/src/components/SDKProvider.test.tsx +23 -58
- package/src/components/SDKProvider.tsx +38 -30
- package/src/components/SanityApp.test.tsx +12 -68
- package/src/components/SanityApp.tsx +88 -65
- package/src/components/auth/AuthBoundary.test.tsx +8 -26
- package/src/components/auth/LoginError.tsx +5 -5
- package/src/config/handles.ts +53 -0
- package/src/context/ComlinkTokenRefresh.test.tsx +27 -10
- package/src/context/DefaultResourceContext.ts +10 -0
- package/src/context/PerspectiveContext.ts +12 -0
- package/src/context/ResourceProvider.test.tsx +99 -19
- package/src/context/ResourceProvider.tsx +103 -37
- package/src/context/ResourcesContext.tsx +7 -0
- package/src/context/SDKStudioContext.test.tsx +33 -28
- package/src/context/SDKStudioContext.ts +6 -0
- package/src/context/renderSanityApp.test.tsx +49 -151
- package/src/context/renderSanityApp.tsx +8 -12
- package/src/hooks/agent/agentActions.test.tsx +1 -1
- package/src/hooks/agent/agentActions.ts +56 -19
- package/src/hooks/auth/useDashboardOrganizationId.test.tsx +8 -2
- package/src/hooks/auth/useVerifyOrgProjects.test.tsx +32 -8
- package/src/hooks/client/useClient.test.tsx +4 -1
- package/src/hooks/client/useClient.ts +0 -1
- package/src/hooks/context/useDefaultResource.test.tsx +25 -0
- package/src/hooks/context/useDefaultResource.ts +30 -0
- package/src/hooks/context/useSanityInstance.test.tsx +2 -140
- package/src/hooks/context/useSanityInstance.ts +9 -53
- package/src/hooks/dashboard/useDispatchIntent.test.ts +24 -15
- package/src/hooks/dashboard/useDispatchIntent.ts +7 -7
- package/src/hooks/dashboard/useManageFavorite.test.tsx +34 -94
- package/src/hooks/dashboard/useManageFavorite.ts +16 -10
- package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +7 -5
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +6 -2
- package/src/hooks/dashboard/useRecordDocumentHistoryEvent.test.ts +2 -0
- package/src/hooks/dashboard/useRecordDocumentHistoryEvent.ts +2 -1
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.test.ts +17 -38
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +12 -19
- package/src/hooks/datasets/useDatasets.test.ts +8 -22
- package/src/hooks/datasets/useDatasets.ts +8 -16
- package/src/hooks/document/useApplyDocumentActions.test.ts +98 -52
- package/src/hooks/document/useApplyDocumentActions.ts +35 -37
- package/src/hooks/document/useDocument.test.tsx +8 -37
- package/src/hooks/document/useDocument.ts +78 -129
- package/src/hooks/document/useDocumentEvent.test.tsx +7 -19
- package/src/hooks/document/useDocumentEvent.ts +21 -19
- package/src/hooks/document/useDocumentPermissions.test.tsx +75 -84
- package/src/hooks/document/useDocumentPermissions.ts +41 -28
- package/src/hooks/document/useDocumentSyncStatus.test.ts +13 -3
- package/src/hooks/document/useDocumentSyncStatus.ts +19 -14
- package/src/hooks/document/useEditDocument.test.tsx +28 -70
- package/src/hooks/document/useEditDocument.ts +29 -149
- package/src/hooks/documents/useDocuments.test.tsx +44 -64
- package/src/hooks/documents/useDocuments.ts +19 -25
- package/src/hooks/helpers/createCallbackHook.test.tsx +19 -13
- package/src/hooks/helpers/createStateSourceHook.test.tsx +10 -10
- package/src/hooks/helpers/createStateSourceHook.tsx +2 -4
- package/src/hooks/helpers/useNormalizedResourceOptions.test.ts +65 -0
- package/src/hooks/helpers/useNormalizedResourceOptions.ts +127 -0
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +27 -34
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +19 -20
- package/src/hooks/presence/usePresence.test.tsx +71 -9
- package/src/hooks/presence/usePresence.ts +28 -3
- package/src/hooks/preview/useDocumentPreview.test.tsx +85 -193
- package/src/hooks/preview/useDocumentPreview.tsx +42 -62
- package/src/hooks/projection/useDocumentProjection.test.tsx +9 -37
- package/src/hooks/projection/useDocumentProjection.ts +9 -82
- package/src/hooks/projects/useProject.test.ts +1 -2
- package/src/hooks/projects/useProject.ts +7 -8
- package/src/hooks/query/useQuery.test.tsx +5 -6
- package/src/hooks/query/useQuery.ts +12 -91
- package/src/hooks/releases/useActiveReleases.test.tsx +2 -2
- package/src/hooks/releases/useActiveReleases.ts +25 -13
- package/src/hooks/releases/usePerspective.test.tsx +9 -17
- package/src/hooks/releases/usePerspective.ts +29 -18
- package/src/hooks/users/useUser.test.tsx +9 -3
- package/src/hooks/users/useUser.ts +1 -1
- package/src/hooks/users/useUsers.test.tsx +5 -2
- package/src/hooks/users/useUsers.ts +1 -1
- package/src/context/SourcesContext.tsx +0 -7
- package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -85
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/sdk-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sanity SDK React toolkit for Content OS",
|
|
6
6
|
"keywords": [
|
|
@@ -47,12 +47,10 @@
|
|
|
47
47
|
"@sanity/message-protocol": "^0.18.0",
|
|
48
48
|
"@sanity/types": "^5.2.0",
|
|
49
49
|
"@types/lodash-es": "^4.17.12",
|
|
50
|
-
"groq": "3.88.1-typegen-experimental.0",
|
|
51
50
|
"lodash-es": "^4.17.21",
|
|
52
|
-
"react-compiler-runtime": "19.1.0-rc.2",
|
|
53
51
|
"react-error-boundary": "^5.0.0",
|
|
54
52
|
"rxjs": "^7.8.2",
|
|
55
|
-
"@sanity/sdk": "
|
|
53
|
+
"@sanity/sdk": "3.0.0-rc.0"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
56
|
"@sanity/browserslist-config": "^1.0.5",
|
|
@@ -77,15 +75,15 @@
|
|
|
77
75
|
"typescript": "^5.8.3",
|
|
78
76
|
"vite": "^6.3.4",
|
|
79
77
|
"vitest": "^3.2.4",
|
|
80
|
-
"@repo/package.bundle": "3.82.0",
|
|
81
78
|
"@repo/config-eslint": "0.0.0",
|
|
82
79
|
"@repo/config-test": "0.0.1",
|
|
83
|
-
"@repo/package.
|
|
84
|
-
"@repo/tsconfig": "0.0.1"
|
|
80
|
+
"@repo/package.bundle": "3.82.0",
|
|
81
|
+
"@repo/tsconfig": "0.0.1",
|
|
82
|
+
"@repo/package.config": "0.0.1"
|
|
85
83
|
},
|
|
86
84
|
"peerDependencies": {
|
|
87
|
-
"react": "^
|
|
88
|
-
"react-dom": "^
|
|
85
|
+
"react": "^19.2.0",
|
|
86
|
+
"react-dom": "^19.2.0"
|
|
89
87
|
},
|
|
90
88
|
"engines": {
|
|
91
89
|
"node": ">=20.19"
|
package/src/_exports/index.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './sdk-react.ts'
|
|
2
2
|
export * from '@sanity/sdk'
|
|
3
|
+
|
|
4
|
+
// Explicitly re-export React-layer handle types to resolve ambiguity with @sanity/sdk versions.
|
|
5
|
+
// These shadow the core (strict) versions for @sanity/sdk-react consumers.
|
|
6
|
+
export {type DocumentHandle, type DocumentTypeHandle, type ResourceHandle} from './sdk-react.ts'
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module exports
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
// React-layer handle types (relaxed) — shadow core versions for @sanity/sdk-react consumers.
|
|
6
|
+
// resource is optional and resolved from context when not provided.
|
|
4
7
|
export {AuthBoundary, type AuthBoundaryProps} from '../components/auth/AuthBoundary'
|
|
5
8
|
export {SanityApp, type SanityAppProps} from '../components/SanityApp'
|
|
6
9
|
export {SDKProvider, type SDKProviderProps} from '../components/SDKProvider'
|
|
10
|
+
export {
|
|
11
|
+
type DocumentHandle as DocumentHandle,
|
|
12
|
+
type DocumentTypeHandle as DocumentTypeHandle,
|
|
13
|
+
type ResourceHandle as ResourceHandle,
|
|
14
|
+
} from '../config/handles'
|
|
7
15
|
export {ComlinkTokenRefreshProvider} from '../context/ComlinkTokenRefresh'
|
|
8
16
|
export {renderSanityApp} from '../context/renderSanityApp'
|
|
9
17
|
export {ResourceProvider, type ResourceProviderProps} from '../context/ResourceProvider'
|
|
@@ -40,6 +48,7 @@ export {
|
|
|
40
48
|
type WindowConnection,
|
|
41
49
|
type WindowMessageHandler,
|
|
42
50
|
} from '../hooks/comlink/useWindowConnection'
|
|
51
|
+
export {useResource} from '../hooks/context/useDefaultResource'
|
|
43
52
|
export {useSanityInstance} from '../hooks/context/useSanityInstance'
|
|
44
53
|
export {useDashboardNavigate} from '../hooks/dashboard/useDashboardNavigate'
|
|
45
54
|
export {useDispatchIntent} from '../hooks/dashboard/useDispatchIntent'
|
|
@@ -88,4 +97,11 @@ export {type UsersResult, useUsers} from '../hooks/users/useUsers'
|
|
|
88
97
|
export {REACT_SDK_VERSION} from '../version'
|
|
89
98
|
export {type DatasetsResponse, type SanityProjectMember} from '@sanity/client'
|
|
90
99
|
export type {Status as ComlinkStatus} from '@sanity/comlink'
|
|
100
|
+
|
|
101
|
+
// Strict core versions — available for users who need explicit resource
|
|
102
|
+
export {
|
|
103
|
+
type DocumentHandle as StrictDocumentHandle,
|
|
104
|
+
type DocumentTypeHandle as StrictDocumentTypeHandle,
|
|
105
|
+
type ResourceHandle as StrictResourceHandle,
|
|
106
|
+
} from '@sanity/sdk'
|
|
91
107
|
export {type SanityDocument, type SortOrderingItem} from '@sanity/types'
|
|
@@ -4,31 +4,16 @@ import {describe, expect, it, vi} from 'vitest'
|
|
|
4
4
|
|
|
5
5
|
import {SDKProvider} from './SDKProvider'
|
|
6
6
|
|
|
7
|
-
// Mock ResourceProvider to test nesting behavior
|
|
8
7
|
vi.mock('../context/ResourceProvider', () => ({
|
|
9
|
-
ResourceProvider: ({
|
|
10
|
-
children,
|
|
11
|
-
...props
|
|
12
|
-
}: {
|
|
13
|
-
children: React.ReactNode
|
|
14
|
-
projectId?: string
|
|
15
|
-
dataset?: string
|
|
16
|
-
}) => {
|
|
8
|
+
ResourceProvider: ({children, resource}: {children: React.ReactNode; resource?: unknown}) => {
|
|
17
9
|
return (
|
|
18
|
-
<div
|
|
19
|
-
data-testid="resource-provider"
|
|
20
|
-
data-config={JSON.stringify({
|
|
21
|
-
projectId: props.projectId,
|
|
22
|
-
dataset: props.dataset,
|
|
23
|
-
})}
|
|
24
|
-
>
|
|
10
|
+
<div data-testid="resource-provider" data-resource={JSON.stringify(resource ?? null)}>
|
|
25
11
|
{children}
|
|
26
12
|
</div>
|
|
27
13
|
)
|
|
28
14
|
},
|
|
29
15
|
}))
|
|
30
16
|
|
|
31
|
-
// Mock AuthBoundary
|
|
32
17
|
vi.mock('./auth/AuthBoundary', () => ({
|
|
33
18
|
AuthBoundary: ({children}: {children: React.ReactNode}) => {
|
|
34
19
|
return <div data-testid="auth-boundary">{children}</div>
|
|
@@ -36,66 +21,46 @@ vi.mock('./auth/AuthBoundary', () => ({
|
|
|
36
21
|
}))
|
|
37
22
|
|
|
38
23
|
describe('SDKProvider', () => {
|
|
39
|
-
it('renders single ResourceProvider with AuthBoundary
|
|
40
|
-
const config = {
|
|
41
|
-
|
|
42
|
-
dataset: 'production',
|
|
24
|
+
it('renders a single ResourceProvider with AuthBoundary', () => {
|
|
25
|
+
const config = {}
|
|
26
|
+
const resources = {
|
|
27
|
+
default: {projectId: 'test-project', dataset: 'production'},
|
|
43
28
|
}
|
|
44
29
|
|
|
45
|
-
const {
|
|
46
|
-
<SDKProvider config={
|
|
30
|
+
const {getByTestId} = render(
|
|
31
|
+
<SDKProvider config={config} resources={resources} fallback={<div>Loading...</div>}>
|
|
47
32
|
<div>Child Content</div>
|
|
48
33
|
</SDKProvider>,
|
|
49
34
|
)
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(providers.length).toBe(1)
|
|
54
|
-
|
|
55
|
-
// Should create an AuthBoundary inside
|
|
36
|
+
const provider = getByTestId('resource-provider')
|
|
37
|
+
expect(provider).toBeInTheDocument()
|
|
56
38
|
expect(getByTestId('auth-boundary')).toBeInTheDocument()
|
|
57
39
|
|
|
58
|
-
//
|
|
59
|
-
expect(JSON.parse(
|
|
40
|
+
// resource prop should be the default resource
|
|
41
|
+
expect(JSON.parse(provider.getAttribute('data-resource') || 'null')).toEqual({
|
|
60
42
|
projectId: 'test-project',
|
|
61
43
|
dataset: 'production',
|
|
62
44
|
})
|
|
63
45
|
})
|
|
64
46
|
|
|
65
|
-
it('renders
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
projectId: 'project-2',
|
|
73
|
-
dataset: 'staging',
|
|
74
|
-
},
|
|
75
|
-
]
|
|
47
|
+
it('renders with multiple named resources', () => {
|
|
48
|
+
const config = {}
|
|
49
|
+
const resources = {
|
|
50
|
+
default: {projectId: 'project-1', dataset: 'production'},
|
|
51
|
+
secondary: {projectId: 'project-2', dataset: 'staging'},
|
|
52
|
+
}
|
|
76
53
|
|
|
77
|
-
const {
|
|
78
|
-
<SDKProvider config={
|
|
54
|
+
const {getByTestId} = render(
|
|
55
|
+
<SDKProvider config={config} resources={resources} fallback={<div>Loading...</div>}>
|
|
79
56
|
<div>Child Content</div>
|
|
80
57
|
</SDKProvider>,
|
|
81
58
|
)
|
|
82
59
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(providers.length).toBe(2)
|
|
86
|
-
|
|
87
|
-
// Should create an AuthBoundary inside the innermost provider
|
|
88
|
-
expect(getByTestId('auth-boundary')).toBeInTheDocument()
|
|
89
|
-
|
|
90
|
-
// Verify each provider has the correct config - order is based on how SDKProvider creates nestings
|
|
91
|
-
// The first provider contains config[1]
|
|
92
|
-
expect(JSON.parse(providers[0].getAttribute('data-config') || '{}')).toEqual({
|
|
93
|
-
projectId: 'project-2',
|
|
94
|
-
dataset: 'staging',
|
|
95
|
-
})
|
|
60
|
+
const provider = getByTestId('resource-provider')
|
|
61
|
+
expect(provider).toBeInTheDocument()
|
|
96
62
|
|
|
97
|
-
|
|
98
|
-
expect(JSON.parse(providers[1].getAttribute('data-config') || '{}')).toEqual({
|
|
63
|
+
expect(JSON.parse(provider.getAttribute('data-resource') || 'null')).toEqual({
|
|
99
64
|
projectId: 'project-1',
|
|
100
65
|
dataset: 'production',
|
|
101
66
|
})
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_RESOURCE_NAME,
|
|
3
|
+
type DocumentResource,
|
|
4
|
+
isDatasetResource,
|
|
5
|
+
type SanityConfig,
|
|
6
|
+
} from '@sanity/sdk'
|
|
2
7
|
import {type ReactElement, type ReactNode, useMemo} from 'react'
|
|
3
8
|
|
|
4
9
|
import {ResourceProvider} from '../context/ResourceProvider'
|
|
5
|
-
import {
|
|
10
|
+
import {ResourcesContext} from '../context/ResourcesContext'
|
|
6
11
|
import {AuthBoundary, type AuthBoundaryProps} from './auth/AuthBoundary'
|
|
7
12
|
|
|
8
13
|
/**
|
|
@@ -10,48 +15,51 @@ import {AuthBoundary, type AuthBoundaryProps} from './auth/AuthBoundary'
|
|
|
10
15
|
*/
|
|
11
16
|
export interface SDKProviderProps extends AuthBoundaryProps {
|
|
12
17
|
children: ReactNode
|
|
13
|
-
config: SanityConfig
|
|
18
|
+
config: SanityConfig
|
|
19
|
+
/**
|
|
20
|
+
* Named document resources map. Provided to `ResourcesContext` for
|
|
21
|
+
* name-based resource resolution in hooks.
|
|
22
|
+
*/
|
|
23
|
+
resources?: Record<string, DocumentResource>
|
|
14
24
|
fallback: ReactNode
|
|
15
|
-
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Collects unique project IDs from a resources map.
|
|
29
|
+
*/
|
|
30
|
+
function collectProjectIds(resources: Record<string, DocumentResource>): string[] {
|
|
31
|
+
const ids = new Set<string>()
|
|
32
|
+
for (const res of Object.values(resources)) {
|
|
33
|
+
if (isDatasetResource(res)) ids.add(res.projectId)
|
|
34
|
+
}
|
|
35
|
+
return [...ids]
|
|
16
36
|
}
|
|
17
37
|
|
|
18
38
|
/**
|
|
19
39
|
* @internal
|
|
20
40
|
*
|
|
21
41
|
* Top-level context provider that provides access to the Sanity SDK.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
42
|
+
*
|
|
43
|
+
* Creates a single `ResourceProvider` (and therefore a single `SanityInstance`)
|
|
44
|
+
* for the given config. Resource resolution is handled by `ResourcesContext`
|
|
45
|
+
* and the `"default"` named resource.
|
|
24
46
|
*/
|
|
25
47
|
export function SDKProvider({
|
|
26
48
|
children,
|
|
27
49
|
config,
|
|
50
|
+
resources = {},
|
|
28
51
|
fallback,
|
|
29
52
|
...props
|
|
30
53
|
}: SDKProviderProps): ReactElement {
|
|
31
|
-
|
|
32
|
-
// ResourceProvider nesting makes the last one the default
|
|
33
|
-
const configs = (Array.isArray(config) ? config : [config]).slice().reverse()
|
|
34
|
-
const projectIds = configs.map((c) => c.projectId).filter((id): id is string => !!id)
|
|
35
|
-
|
|
36
|
-
// Memoize sources to prevent creating a new empty object on every render
|
|
37
|
-
const sourcesValue = useMemo(() => props.sources ?? {}, [props.sources])
|
|
54
|
+
const projectIds = useMemo(() => collectProjectIds(resources), [resources])
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
const createNestedProviders = (index: number): ReactElement => {
|
|
41
|
-
if (index >= configs.length) {
|
|
42
|
-
return (
|
|
43
|
-
<AuthBoundary {...props} projectIds={projectIds}>
|
|
44
|
-
<SourcesContext.Provider value={sourcesValue}>{children}</SourcesContext.Provider>
|
|
45
|
-
</AuthBoundary>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<ResourceProvider {...configs[index]} fallback={fallback}>
|
|
51
|
-
{createNestedProviders(index + 1)}
|
|
52
|
-
</ResourceProvider>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
56
|
+
const rootResource = useMemo(() => resources[DEFAULT_RESOURCE_NAME], [resources])
|
|
55
57
|
|
|
56
|
-
return
|
|
58
|
+
return (
|
|
59
|
+
<ResourceProvider {...config} resource={rootResource} fallback={fallback}>
|
|
60
|
+
<AuthBoundary {...props} projectIds={projectIds}>
|
|
61
|
+
<ResourcesContext.Provider value={resources}>{children}</ResourcesContext.Provider>
|
|
62
|
+
</AuthBoundary>
|
|
63
|
+
</ResourceProvider>
|
|
64
|
+
)
|
|
57
65
|
}
|
|
@@ -58,14 +58,11 @@ describe('SanityApp', () => {
|
|
|
58
58
|
mockSDKProviderComponent.mockClear()
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it('renders SDKProvider with a single
|
|
62
|
-
const
|
|
63
|
-
projectId: 'test-project',
|
|
64
|
-
dataset: 'production',
|
|
65
|
-
}
|
|
61
|
+
it('renders SDKProvider with a single resource', () => {
|
|
62
|
+
const singleResource = {projectId: 'test-project', dataset: 'production'}
|
|
66
63
|
|
|
67
64
|
render(
|
|
68
|
-
<SanityApp
|
|
65
|
+
<SanityApp resources={{default: singleResource}} fallback={<div>Loading...</div>}>
|
|
69
66
|
<div>Child Content</div>
|
|
70
67
|
</SanityApp>,
|
|
71
68
|
)
|
|
@@ -80,60 +77,17 @@ describe('SanityApp', () => {
|
|
|
80
77
|
expect(firstCallArgs1).toBeDefined()
|
|
81
78
|
expect(firstCallArgs1.length).toBeGreaterThan(0)
|
|
82
79
|
const props = firstCallArgs1[0] as unknown as SDKProviderProps
|
|
83
|
-
const config = props?.config
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
expect(config).toEqual(singleConfig)
|
|
81
|
+
expect(props.resources).toEqual({default: singleResource})
|
|
87
82
|
expect(props.fallback).toBeTruthy()
|
|
88
83
|
})
|
|
89
84
|
|
|
90
|
-
it('renders SDKProvider with multiple configs in original order', () => {
|
|
91
|
-
const multipleConfigs = [
|
|
92
|
-
{
|
|
93
|
-
projectId: 'project-1',
|
|
94
|
-
dataset: 'production',
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
projectId: 'project-2',
|
|
98
|
-
dataset: 'staging',
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
projectId: 'project-3',
|
|
102
|
-
dataset: 'development',
|
|
103
|
-
},
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
render(
|
|
107
|
-
<SanityApp config={multipleConfigs} fallback={<div>Loading...</div>}>
|
|
108
|
-
<div>Child Content</div>
|
|
109
|
-
</SanityApp>,
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
// Check that the SDKProvider is rendered
|
|
113
|
-
expect(screen.getByTestId('sdk-provider')).toBeInTheDocument()
|
|
114
|
-
|
|
115
|
-
// Verify SDKProvider was called with the correct props
|
|
116
|
-
expect(mockSDKProviderComponent).toHaveBeenCalledTimes(1)
|
|
117
|
-
const sdkProviderCalls = mockSDKProviderComponent.mock.calls
|
|
118
|
-
const firstCallArgs2 = sdkProviderCalls[0]
|
|
119
|
-
expect(firstCallArgs2).toBeDefined()
|
|
120
|
-
expect(firstCallArgs2.length).toBeGreaterThan(0)
|
|
121
|
-
const props = firstCallArgs2[0] as unknown as SDKProviderProps
|
|
122
|
-
const config = props?.config
|
|
123
|
-
|
|
124
|
-
// Config should be passed directly to SDKProvider
|
|
125
|
-
expect(config).toEqual(multipleConfigs)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
85
|
it('handles iframe environment correctly', async () => {
|
|
129
86
|
// Mock window.self and window.top to simulate iframe environment
|
|
130
87
|
const originalTop = window.top
|
|
131
88
|
const originalSelf = window.self
|
|
132
89
|
|
|
133
|
-
const mockSanityConfig: SanityConfig = {
|
|
134
|
-
projectId: 'test-project',
|
|
135
|
-
dataset: 'test-dataset',
|
|
136
|
-
}
|
|
90
|
+
const mockSanityConfig: SanityConfig = {}
|
|
137
91
|
|
|
138
92
|
const mockTop = {}
|
|
139
93
|
Object.defineProperty(window, 'top', {
|
|
@@ -146,7 +100,7 @@ describe('SanityApp', () => {
|
|
|
146
100
|
})
|
|
147
101
|
|
|
148
102
|
render(
|
|
149
|
-
<SanityApp config={
|
|
103
|
+
<SanityApp config={mockSanityConfig} fallback={<div>Fallback</div>}>
|
|
150
104
|
<div>Test Child</div>
|
|
151
105
|
</SanityApp>,
|
|
152
106
|
)
|
|
@@ -177,10 +131,7 @@ describe('SanityApp', () => {
|
|
|
177
131
|
href: 'http://sanity-test.app',
|
|
178
132
|
}
|
|
179
133
|
|
|
180
|
-
const mockSanityConfig: SanityConfig = {
|
|
181
|
-
projectId: 'test-project',
|
|
182
|
-
dataset: 'test-dataset',
|
|
183
|
-
}
|
|
134
|
+
const mockSanityConfig: SanityConfig = {}
|
|
184
135
|
|
|
185
136
|
Object.defineProperty(window, 'location', {
|
|
186
137
|
value: mockLocation,
|
|
@@ -188,7 +139,7 @@ describe('SanityApp', () => {
|
|
|
188
139
|
})
|
|
189
140
|
|
|
190
141
|
render(
|
|
191
|
-
<SanityApp config={
|
|
142
|
+
<SanityApp config={mockSanityConfig} fallback={<div>Fallback</div>}>
|
|
192
143
|
<div>Test Child</div>
|
|
193
144
|
</SanityApp>,
|
|
194
145
|
)
|
|
@@ -241,10 +192,7 @@ describe('SanityApp', () => {
|
|
|
241
192
|
it('does not redirect to core if not inside iframe and local url', async () => {
|
|
242
193
|
const originalLocation = window.location
|
|
243
194
|
|
|
244
|
-
const mockSanityConfig: SanityConfig = {
|
|
245
|
-
projectId: 'test-project',
|
|
246
|
-
dataset: 'test-dataset',
|
|
247
|
-
}
|
|
195
|
+
const mockSanityConfig: SanityConfig = {}
|
|
248
196
|
|
|
249
197
|
const mockLocation = {
|
|
250
198
|
replace: vi.fn(),
|
|
@@ -257,7 +205,7 @@ describe('SanityApp', () => {
|
|
|
257
205
|
})
|
|
258
206
|
|
|
259
207
|
render(
|
|
260
|
-
<SanityApp config={
|
|
208
|
+
<SanityApp config={mockSanityConfig} fallback={<div>Fallback</div>}>
|
|
261
209
|
<div>Test Child</div>
|
|
262
210
|
</SanityApp>,
|
|
263
211
|
)
|
|
@@ -285,8 +233,6 @@ describe('SanityApp', () => {
|
|
|
285
233
|
}
|
|
286
234
|
|
|
287
235
|
const mockSanityConfig: SanityConfig = {
|
|
288
|
-
projectId: 'test-project',
|
|
289
|
-
dataset: 'test-dataset',
|
|
290
236
|
studio: {},
|
|
291
237
|
}
|
|
292
238
|
|
|
@@ -296,7 +242,7 @@ describe('SanityApp', () => {
|
|
|
296
242
|
})
|
|
297
243
|
|
|
298
244
|
render(
|
|
299
|
-
<SanityApp config={
|
|
245
|
+
<SanityApp config={mockSanityConfig} fallback={<div>Fallback</div>}>
|
|
300
246
|
<div>Test Child</div>
|
|
301
247
|
</SanityApp>,
|
|
302
248
|
)
|
|
@@ -325,8 +271,6 @@ describe('SanityApp', () => {
|
|
|
325
271
|
}
|
|
326
272
|
|
|
327
273
|
const mockSanityConfig: SanityConfig = {
|
|
328
|
-
projectId: 'test-project',
|
|
329
|
-
dataset: 'test-dataset',
|
|
330
274
|
studio: {},
|
|
331
275
|
}
|
|
332
276
|
|
|
@@ -336,7 +280,7 @@ describe('SanityApp', () => {
|
|
|
336
280
|
})
|
|
337
281
|
|
|
338
282
|
render(
|
|
339
|
-
<SanityApp config={
|
|
283
|
+
<SanityApp config={mockSanityConfig} fallback={<div>Fallback</div>}>
|
|
340
284
|
<div>Test Child</div>
|
|
341
285
|
</SanityApp>,
|
|
342
286
|
)
|