@sanity/sdk-react 2.9.0 → 2.11.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.
Files changed (72) hide show
  1. package/dist/index.d.ts +338 -215
  2. package/dist/index.js +564 -342
  3. package/dist/index.js.map +1 -1
  4. package/package.json +9 -14
  5. package/src/_exports/index.ts +2 -0
  6. package/src/_exports/sdk-react.ts +8 -0
  7. package/src/components/SDKProvider.test.tsx +5 -12
  8. package/src/components/SDKProvider.tsx +58 -28
  9. package/src/components/SanityApp.tsx +2 -2
  10. package/src/components/auth/AuthBoundary.tsx +8 -1
  11. package/src/components/auth/DashboardAccessRequest.tsx +37 -0
  12. package/src/components/auth/LoginError.test.tsx +191 -5
  13. package/src/components/auth/LoginError.tsx +100 -56
  14. package/src/components/errors/ChunkLoadError.test.tsx +59 -0
  15. package/src/components/errors/ChunkLoadError.tsx +56 -0
  16. package/src/components/errors/chunkReloadStorage.ts +57 -0
  17. package/src/config/handles.ts +55 -0
  18. package/src/constants.ts +5 -0
  19. package/src/context/DefaultResourceContext.ts +10 -0
  20. package/src/context/PerspectiveContext.ts +12 -0
  21. package/src/context/ResourceProvider.test.tsx +2 -2
  22. package/src/context/ResourceProvider.tsx +56 -51
  23. package/src/context/ResourcesContext.tsx +7 -0
  24. package/src/context/SanityInstanceProvider.test.tsx +100 -0
  25. package/src/context/SanityInstanceProvider.tsx +71 -0
  26. package/src/hooks/agent/agentActions.ts +55 -38
  27. package/src/hooks/auth/useVerifyOrgProjects.tsx +13 -6
  28. package/src/hooks/context/useResource.test.tsx +32 -0
  29. package/src/hooks/context/useResource.ts +24 -0
  30. package/src/hooks/context/useSanityInstance.test.tsx +42 -111
  31. package/src/hooks/context/useSanityInstance.ts +28 -50
  32. package/src/hooks/dashboard/useDispatchIntent.test.ts +11 -7
  33. package/src/hooks/dashboard/useDispatchIntent.ts +7 -7
  34. package/src/hooks/dashboard/useManageFavorite.test.tsx +16 -12
  35. package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.test.ts +15 -15
  36. package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +13 -17
  37. package/src/hooks/document/{useApplyDocumentActions.test.ts → useApplyDocumentActions.test.tsx} +46 -81
  38. package/src/hooks/document/useApplyDocumentActions.ts +33 -67
  39. package/src/hooks/document/useDocument.ts +4 -6
  40. package/src/hooks/document/useDocumentEvent.ts +8 -7
  41. package/src/hooks/document/useDocumentPermissions.test.tsx +60 -152
  42. package/src/hooks/document/useDocumentPermissions.ts +78 -55
  43. package/src/hooks/document/useDocumentSyncStatus.ts +2 -2
  44. package/src/hooks/document/useEditDocument.test.tsx +25 -60
  45. package/src/hooks/document/useEditDocument.ts +3 -3
  46. package/src/hooks/documents/useDocuments.ts +19 -11
  47. package/src/hooks/helpers/createStateSourceHook.tsx +1 -2
  48. package/src/hooks/helpers/useNormalizedResourceOptions.test.tsx +253 -0
  49. package/src/hooks/helpers/useNormalizedResourceOptions.ts +169 -0
  50. package/src/hooks/helpers/useTrackHookUsage.ts +2 -2
  51. package/src/hooks/organizations/useOrganization.test-d.ts +53 -0
  52. package/src/hooks/organizations/useOrganization.test.ts +65 -0
  53. package/src/hooks/organizations/useOrganization.ts +40 -0
  54. package/src/hooks/organizations/useOrganizations.test-d.ts +55 -0
  55. package/src/hooks/organizations/useOrganizations.test.ts +85 -0
  56. package/src/hooks/organizations/useOrganizations.ts +45 -0
  57. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +29 -14
  58. package/src/hooks/presence/usePresence.test.tsx +56 -9
  59. package/src/hooks/presence/usePresence.ts +16 -4
  60. package/src/hooks/preview/useDocumentPreview.tsx +8 -10
  61. package/src/hooks/projection/useDocumentProjection.ts +7 -9
  62. package/src/hooks/projects/useProject.test-d.ts +49 -0
  63. package/src/hooks/projects/useProject.ts +33 -41
  64. package/src/hooks/projects/useProjects.test-d.ts +49 -0
  65. package/src/hooks/projects/useProjects.ts +17 -23
  66. package/src/hooks/query/useQuery.ts +11 -10
  67. package/src/hooks/releases/useActiveReleases.ts +14 -14
  68. package/src/hooks/releases/usePerspective.ts +11 -16
  69. package/src/hooks/users/useUser.ts +1 -1
  70. package/src/hooks/users/useUsers.ts +1 -1
  71. package/src/context/SourcesContext.tsx +0 -7
  72. package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -107
@@ -1,7 +1,9 @@
1
- import {applyDocumentActions, type SanityInstance} from '@sanity/sdk'
1
+ import {applyDocumentActions, createSanityInstance} from '@sanity/sdk'
2
+ import {renderHook as reactRenderHook} from '@testing-library/react'
2
3
  import {describe, it} from 'vitest'
3
4
 
4
5
  import {renderHook} from '../../../test/test-utils'
6
+ import {SanityInstanceContext} from '../../context/SanityInstanceContext'
5
7
  import {useSanityInstance} from '../context/useSanityInstance'
6
8
  import {useApplyDocumentActions} from './useApplyDocumentActions'
7
9
 
@@ -12,18 +14,7 @@ vi.mock('@sanity/sdk', async (importOriginal) => {
12
14
 
13
15
  vi.mock('../context/useSanityInstance')
14
16
 
15
- // These are quite fragile mocks, but they are useful enough for now.
16
- const instances: Record<string, SanityInstance | undefined> = {
17
- 'p123.d': {__id: 'p123.d'} as unknown as SanityInstance,
18
- 'p.d123': {__id: 'p.d123'} as unknown as SanityInstance,
19
- 'p123.d123': {__id: 'p123.d123'} as unknown as SanityInstance,
20
- }
21
-
22
- const instance = {
23
- match({projectId = 'p', dataset = 'd'}): SanityInstance | undefined {
24
- return instances[`${projectId}.${dataset}`]
25
- },
26
- } as unknown as SanityInstance
17
+ const instance = createSanityInstance({projectId: 'p', dataset: 'd'})
27
18
 
28
19
  describe('useApplyDocumentActions', () => {
29
20
  beforeEach(() => {
@@ -31,7 +22,7 @@ describe('useApplyDocumentActions', () => {
31
22
  vi.mocked(useSanityInstance).mockReturnValueOnce(instance)
32
23
  })
33
24
 
34
- it('uses the SanityInstance', async () => {
25
+ it('uses the effective context resource', async () => {
35
26
  const {result} = renderHook(() => useApplyDocumentActions())
36
27
  result.current({
37
28
  type: 'document.edit',
@@ -45,43 +36,28 @@ describe('useApplyDocumentActions', () => {
45
36
  type: 'document.edit',
46
37
  documentType: 'post',
47
38
  documentId: 'abc',
39
+ // resource named in test-utils
40
+ resource: {projectId: 'test', dataset: 'test'},
48
41
  },
49
42
  ],
43
+ resource: {projectId: 'test', dataset: 'test'},
50
44
  })
51
45
  })
52
46
 
53
- it('uses SanityInstance.match when projectId is overrideen', async () => {
54
- const {result} = renderHook(() => useApplyDocumentActions())
55
- result.current({
56
- type: 'document.edit',
57
- documentType: 'post',
58
- documentId: 'abc',
59
-
60
- projectId: 'p123',
61
- })
62
-
63
- expect(applyDocumentActions).toHaveBeenCalledExactlyOnceWith(instances['p123.d'], {
64
- actions: [
65
- {
66
- type: 'document.edit',
67
- documentType: 'post',
68
- documentId: 'abc',
69
-
70
- projectId: 'p123',
71
- },
72
- ],
73
- })
74
- })
75
-
76
- it('uses SanityInstance when dataset is overrideen', async () => {
77
- const {result} = renderHook(() => useApplyDocumentActions())
78
- result.current({
79
- type: 'document.edit',
80
- documentType: 'post',
81
- documentId: 'abc',
82
-
83
- dataset: 'd123',
47
+ it('uses the SanityInstance when resource is not provided', async () => {
48
+ const {result} = reactRenderHook(() => useApplyDocumentActions(), {
49
+ wrapper: ({children}) => (
50
+ <SanityInstanceContext.Provider value={instance}>{children}</SanityInstanceContext.Provider>
51
+ ),
84
52
  })
53
+ result.current(
54
+ {
55
+ type: 'document.edit',
56
+ documentType: 'post',
57
+ documentId: 'abc',
58
+ },
59
+ {},
60
+ )
85
61
 
86
62
  expect(applyDocumentActions).toHaveBeenCalledExactlyOnceWith(instance, {
87
63
  actions: [
@@ -89,51 +65,36 @@ describe('useApplyDocumentActions', () => {
89
65
  type: 'document.edit',
90
66
  documentType: 'post',
91
67
  documentId: 'abc',
92
-
93
- dataset: 'd123',
68
+ resource: {projectId: 'p', dataset: 'd'},
94
69
  },
95
70
  ],
71
+ resource: {projectId: 'p', dataset: 'd'},
96
72
  })
97
73
  })
98
74
 
99
- it('uses SanityInstance.amcth when projectId and dataset is overrideen', async () => {
75
+ it('resolves resource from projectId and dataset in action', async () => {
100
76
  const {result} = renderHook(() => useApplyDocumentActions())
101
77
  result.current({
102
78
  type: 'document.edit',
103
79
  documentType: 'post',
104
80
  documentId: 'abc',
105
-
106
- projectId: 'p123',
81
+ projectId: 'p',
107
82
  dataset: 'd123',
108
83
  })
109
84
 
110
- expect(applyDocumentActions).toHaveBeenCalledExactlyOnceWith(instances['p123.d123'], {
85
+ expect(applyDocumentActions).toHaveBeenCalledExactlyOnceWith(instance, {
111
86
  actions: [
112
87
  {
113
88
  type: 'document.edit',
114
89
  documentType: 'post',
115
90
  documentId: 'abc',
116
-
117
- projectId: 'p123',
118
- dataset: 'd123',
91
+ resource: {projectId: 'p', dataset: 'd123'},
119
92
  },
120
93
  ],
94
+ resource: {projectId: 'p', dataset: 'd123'},
121
95
  })
122
96
  })
123
97
 
124
- it("throws if SanityInstance.match doesn't find anything", async () => {
125
- const {result} = renderHook(() => useApplyDocumentActions())
126
- expect(() => {
127
- result.current({
128
- type: 'document.edit',
129
- documentType: 'post',
130
- documentId: 'abc',
131
-
132
- projectId: 'other',
133
- })
134
- }).toThrow()
135
- })
136
-
137
98
  it('throws when actions have mismatched project IDs', async () => {
138
99
  const {result} = renderHook(() => useApplyDocumentActions())
139
100
  expect(() => {
@@ -143,15 +104,17 @@ describe('useApplyDocumentActions', () => {
143
104
  documentType: 'post',
144
105
  documentId: 'abc',
145
106
  projectId: 'p123',
107
+ dataset: 'd',
146
108
  },
147
109
  {
148
110
  type: 'document.edit',
149
111
  documentType: 'post',
150
112
  documentId: 'def',
151
113
  projectId: 'p456',
114
+ dataset: 'd',
152
115
  },
153
116
  ])
154
- }).toThrow(/Mismatched project IDs found in actions/)
117
+ }).toThrow(/Mismatched resources found in actions/)
155
118
  })
156
119
 
157
120
  it('throws when actions have mismatched datasets', async () => {
@@ -173,10 +136,10 @@ describe('useApplyDocumentActions', () => {
173
136
  dataset: 'd2',
174
137
  },
175
138
  ])
176
- }).toThrow(/Mismatched datasets found in actions/)
139
+ }).toThrow(/Mismatched resources found in actions/)
177
140
  })
178
141
 
179
- it('throws when actions have mismatched sources', async () => {
142
+ it('throws when actions have mismatched resources', async () => {
180
143
  const {result} = renderHook(() => useApplyDocumentActions())
181
144
  expect(() => {
182
145
  result.current([
@@ -184,19 +147,19 @@ describe('useApplyDocumentActions', () => {
184
147
  type: 'document.edit',
185
148
  documentType: 'post',
186
149
  documentId: 'abc',
187
- source: {projectId: 'p', dataset: 'd1'},
150
+ resource: {projectId: 'p', dataset: 'd1'},
188
151
  },
189
152
  {
190
153
  type: 'document.edit',
191
154
  documentType: 'post',
192
155
  documentId: 'def',
193
- source: {projectId: 'p', dataset: 'd2'},
156
+ resource: {projectId: 'p', dataset: 'd2'},
194
157
  },
195
158
  ])
196
- }).toThrow(/Mismatched sources found in actions/)
159
+ }).toThrow(/Mismatched resources found in actions/)
197
160
  })
198
161
 
199
- it('throws when mixing projectId and source (projectId first)', async () => {
162
+ it('throws when mixing projectId/dataset and resource with a mismatch (projectId first)', async () => {
200
163
  const {result} = renderHook(() => useApplyDocumentActions())
201
164
  expect(() => {
202
165
  result.current([
@@ -204,19 +167,20 @@ describe('useApplyDocumentActions', () => {
204
167
  type: 'document.edit',
205
168
  documentType: 'post',
206
169
  documentId: 'abc',
207
- projectId: 'p',
170
+ projectId: 'p1',
171
+ dataset: 'd',
208
172
  },
209
173
  {
210
174
  type: 'document.edit',
211
175
  documentType: 'post',
212
176
  documentId: 'def',
213
- source: {projectId: 'p', dataset: 'd'},
177
+ resource: {projectId: 'p2', dataset: 'd'},
214
178
  },
215
179
  ])
216
- }).toThrow(/Mismatches between projectId\/dataset options and source/)
180
+ }).toThrow(/Mismatched resources found in actions/)
217
181
  })
218
182
 
219
- it('throws when mixing source and projectId (source first)', async () => {
183
+ it('throws when mixing resource and projectId/dataset with a mismatch (resource first)', async () => {
220
184
  const {result} = renderHook(() => useApplyDocumentActions())
221
185
  expect(() => {
222
186
  result.current([
@@ -224,15 +188,16 @@ describe('useApplyDocumentActions', () => {
224
188
  type: 'document.edit',
225
189
  documentType: 'post',
226
190
  documentId: 'abc',
227
- source: {projectId: 'p', dataset: 'd'},
191
+ resource: {projectId: 'p1', dataset: 'd'},
228
192
  },
229
193
  {
230
194
  type: 'document.edit',
231
195
  documentType: 'post',
232
196
  documentId: 'def',
233
- projectId: 'p',
197
+ projectId: 'p2',
198
+ dataset: 'd',
234
199
  },
235
200
  ])
236
- }).toThrow(/Mismatches between projectId\/dataset options and source/)
201
+ }).toThrow(/Mismatched resources found in actions/)
237
202
  })
238
203
  })
@@ -1,18 +1,15 @@
1
- import {
2
- type ActionsResult,
3
- applyDocumentActions,
4
- type ApplyDocumentActionsOptions,
5
- type DocumentAction,
6
- } from '@sanity/sdk'
1
+ import {type ActionsResult, applyDocumentActions, type DocumentAction} from '@sanity/sdk'
2
+ import {isDeepEqual} from '@sanity/sdk/_internal'
7
3
  import {type SanityDocument} from 'groq'
8
4
  import {useContext} from 'react'
9
5
 
10
- import {SourcesContext} from '../../context/SourcesContext'
6
+ import {type ResourceHandle} from '../../config/handles'
7
+ import {ResourcesContext} from '../../context/ResourcesContext'
11
8
  import {useSanityInstance} from '../context/useSanityInstance'
12
9
  import {
13
- normalizeSourceOptions,
14
- type WithSourceNameSupport,
15
- } from '../helpers/useNormalizedSourceOptions'
10
+ normalizeResourceOptions,
11
+ useEffectiveContextResource,
12
+ } from '../helpers/useNormalizedResourceOptions'
16
13
  // this import is used in an `{@link useEditDocument}`
17
14
  // eslint-disable-next-line unused-imports/no-unused-imports, import/consistent-type-specifier-style
18
15
  import type {useEditDocument} from './useEditDocument'
@@ -29,7 +26,7 @@ interface UseApplyDocumentActions {
29
26
  action:
30
27
  | DocumentAction<TDocumentType, TDataset, TProjectId>
31
28
  | DocumentAction<TDocumentType, TDataset, TProjectId>[],
32
- options?: WithSourceNameSupport<ApplyDocumentActionsOptions>,
29
+ options?: ResourceHandle,
33
30
  ) => Promise<ActionsResult<SanityDocument<TDocumentType, `${TProjectId}.${TDataset}`>>>
34
31
  }
35
32
 
@@ -218,74 +215,43 @@ interface UseApplyDocumentActions {
218
215
  */
219
216
  export const useApplyDocumentActions: UseApplyDocumentActions = () => {
220
217
  const instance = useSanityInstance()
221
- const sources = useContext(SourcesContext)
218
+ const resources = useContext(ResourcesContext)
219
+ const effectiveContextResource = useEffectiveContextResource()
222
220
 
223
221
  return (actionOrActions, options) => {
224
222
  const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions]
225
- const normalizedOptions = options ? normalizeSourceOptions(options, sources) : undefined
226
-
227
- let projectId
228
- let dataset
229
- let source
230
- for (const action of actions) {
231
- if (action.projectId) {
232
- if (source) {
233
- throw new Error(
234
- `Mismatches between projectId/dataset options and source in actions. Found projectId "${action.projectId}" and dataset "${action.dataset}" but expected source "${source}".`,
235
- )
236
- }
237
- if (!projectId) projectId = action.projectId
238
- if (action.projectId !== projectId) {
239
- throw new Error(
240
- `Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`,
241
- )
242
- }
223
+ const optionsResource = options
224
+ ? normalizeResourceOptions(options, resources, effectiveContextResource).resource
225
+ : undefined
243
226
 
244
- if (action.dataset) {
245
- if (!dataset) dataset = action.dataset
246
- if (action.dataset !== dataset) {
247
- throw new Error(
248
- `Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`,
249
- )
250
- }
251
- }
252
- }
227
+ const normalizedActions = actions.map((action) =>
228
+ normalizeResourceOptions(action, resources, effectiveContextResource),
229
+ )
230
+ let resource
253
231
 
254
- if (action.source) {
255
- if (!source) source = action.source
256
- if (action.source !== source) {
257
- throw new Error(
258
- `Mismatched sources found in actions. All actions must belong to the same source. Found "${action.source}" but expected "${source}".`,
259
- )
260
- }
261
- if (projectId || dataset) {
262
- throw new Error(
263
- `Mismatches between projectId/dataset options and source in actions. Found "${action.source}" but expected project "${projectId}" and dataset "${dataset}".`,
264
- )
265
- }
266
- }
267
- }
268
-
269
- if (projectId || dataset) {
270
- const actualInstance = instance.match({projectId, dataset})
271
- if (!actualInstance) {
232
+ for (const action of normalizedActions) {
233
+ if (!resource && action.resource) resource = action.resource
234
+ if (!isDeepEqual(action.resource, resource)) {
272
235
  throw new Error(
273
- `Could not find a matching Sanity instance for the requested action: ${JSON.stringify({projectId, dataset}, null, 2)}.
274
- Please ensure there is a ResourceProvider component with a matching configuration in the component hierarchy.`,
236
+ `Mismatched resources found in actions. All actions must belong to the same resource. Found "${JSON.stringify(action.resource)}" but expected "${JSON.stringify(resource)}".`,
275
237
  )
276
238
  }
239
+ }
240
+
241
+ if (optionsResource && resource && !isDeepEqual(optionsResource, resource)) {
242
+ throw new Error(
243
+ `Mismatched resources found in actions. Found top-level resource "${JSON.stringify(optionsResource)}" but expected resource from action handles "${JSON.stringify(resource)}".`,
244
+ )
245
+ }
277
246
 
278
- return applyDocumentActions(actualInstance, {
279
- actions,
280
- source,
281
- ...normalizedOptions,
282
- })
247
+ const effectiveResource = resource ?? optionsResource ?? effectiveContextResource
248
+ if (!effectiveResource) {
249
+ throw new Error('No resource found. Provide a resource via the action handle or context.')
283
250
  }
284
251
 
285
252
  return applyDocumentActions(instance, {
286
- actions,
287
- source,
288
- ...normalizedOptions,
253
+ actions: normalizedActions as DocumentAction[],
254
+ resource: effectiveResource,
289
255
  })
290
256
  }
291
257
  }
@@ -2,11 +2,9 @@ import {type DocumentOptions, getDocumentState, type JsonMatch, resolveDocument}
2
2
  import {type SanityDocument} from 'groq'
3
3
  import {identity} from 'rxjs'
4
4
 
5
+ import {type DocumentHandle} from '../../config/handles'
5
6
  import {createStateSourceHook} from '../helpers/createStateSourceHook'
6
- import {
7
- useNormalizedSourceOptions,
8
- type WithSourceNameSupport,
9
- } from '../helpers/useNormalizedSourceOptions'
7
+ import {useNormalizedResourceOptions} from '../helpers/useNormalizedResourceOptions'
10
8
  import {useTrackHookUsage} from '../helpers/useTrackHookUsage'
11
9
  // used in an `{@link useDocumentProjection}` and `{@link useQuery}`
12
10
  // eslint-disable-next-line import/consistent-type-specifier-style, unused-imports/no-unused-imports
@@ -43,7 +41,7 @@ type UseDocumentOptions<
43
41
  TDocumentType extends string = string,
44
42
  TDataset extends string = string,
45
43
  TProjectId extends string = string,
46
- > = WithSourceNameSupport<DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>>
44
+ > = DocumentHandle<TDocumentType, TDataset, TProjectId> & {path?: TPath}
47
45
 
48
46
  interface UseDocument {
49
47
  /** @internal */
@@ -240,6 +238,6 @@ interface UseDocument {
240
238
  */
241
239
  export const useDocument = wrapHookWithData((options: UseDocumentOptions) => {
242
240
  useTrackHookUsage('useDocument')
243
- const normalizedOptions = useNormalizedSourceOptions(options)
241
+ const normalizedOptions = useNormalizedResourceOptions(options)
244
242
  return useDocumentValue(normalizedOptions)
245
243
  }) as UseDocument
@@ -1,8 +1,9 @@
1
- import {type DatasetHandle, type DocumentEvent, subscribeDocumentEvents} from '@sanity/sdk'
1
+ import {type DocumentEvent, subscribeDocumentEvents} from '@sanity/sdk'
2
2
  import {useCallback, useEffect, useInsertionEffect, useRef} from 'react'
3
3
 
4
+ import {type ResourceHandle} from '../../config/handles'
4
5
  import {useSanityInstance} from '../context/useSanityInstance'
5
- import {useNormalizedSourceOptions} from '../helpers/useNormalizedSourceOptions'
6
+ import {useNormalizedResourceOptions} from '../helpers/useNormalizedResourceOptions'
6
7
  import {useTrackHookUsage} from '../helpers/useTrackHookUsage'
7
8
 
8
9
  /**
@@ -11,7 +12,7 @@ import {useTrackHookUsage} from '../helpers/useTrackHookUsage'
11
12
  export interface UseDocumentEventOptions<
12
13
  TDataset extends string = string,
13
14
  TProjectId extends string = string,
14
- > extends DatasetHandle<TDataset, TProjectId> {
15
+ > extends ResourceHandle<TDataset, TProjectId> {
15
16
  onEvent: (documentEvent: DocumentEvent) => void
16
17
  }
17
18
 
@@ -79,7 +80,7 @@ export function useDocumentEvent<
79
80
  ): void {
80
81
  useTrackHookUsage('useDocumentEvent')
81
82
  // Destructure handler and datasetHandle from options
82
- const normalizedOptions = useNormalizedSourceOptions(options)
83
+ const normalizedOptions = useNormalizedResourceOptions(options)
83
84
  const {onEvent, ...datasetHandle} = normalizedOptions
84
85
  const ref = useRef(onEvent)
85
86
 
@@ -91,11 +92,11 @@ export function useDocumentEvent<
91
92
  return ref.current(documentEvent)
92
93
  }, [])
93
94
 
94
- const instance = useSanityInstance(datasetHandle)
95
+ const instance = useSanityInstance()
95
96
  useEffect(() => {
96
97
  return subscribeDocumentEvents(instance, {
97
98
  eventHandler: stableHandler,
98
- source: datasetHandle.source,
99
+ resource: datasetHandle.resource,
99
100
  })
100
- }, [instance, datasetHandle.source, stableHandler])
101
+ }, [instance, datasetHandle.resource, stableHandler])
101
102
  }