@sanity/sdk-react 2.0.1 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/sdk-react",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "private": false,
5
5
  "description": "Sanity SDK React toolkit for Content OS",
6
6
  "keywords": [
@@ -51,7 +51,7 @@
51
51
  "react-compiler-runtime": "19.1.0-rc.1",
52
52
  "react-error-boundary": "^5.0.0",
53
53
  "rxjs": "^7.8.2",
54
- "@sanity/sdk": "2.0.1"
54
+ "@sanity/sdk": "2.0.2"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@sanity/browserslist-config": "^1.0.5",
@@ -74,11 +74,11 @@
74
74
  "typescript": "^5.8.3",
75
75
  "vite": "^6.3.4",
76
76
  "vitest": "^3.1.2",
77
- "@repo/package.config": "0.0.1",
78
- "@repo/tsconfig": "0.0.1",
79
77
  "@repo/config-eslint": "0.0.0",
80
78
  "@repo/config-test": "0.0.1",
81
- "@repo/package.bundle": "3.82.0"
79
+ "@repo/tsconfig": "0.0.1",
80
+ "@repo/package.bundle": "3.82.0",
81
+ "@repo/package.config": "0.0.1"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "react": "^18.0.0 || ^19.0.0",
@@ -66,6 +66,21 @@ function DashboardTokenRefresh({children}: PropsWithChildren) {
66
66
 
67
67
  if (res.token) {
68
68
  setAuthToken(instance, res.token)
69
+
70
+ // Remove the unauthorized error from the error container
71
+ const errorContainer = document.getElementById('__sanityError')
72
+ if (errorContainer) {
73
+ const hasUnauthorizedError = Array.from(errorContainer.getElementsByTagName('div')).some(
74
+ (div) =>
75
+ div.textContent?.includes(
76
+ 'Uncaught error: Unauthorized - A valid session is required for this endpoint',
77
+ ),
78
+ )
79
+
80
+ if (hasUnauthorizedError) {
81
+ errorContainer.remove()
82
+ }
83
+ }
69
84
  }
70
85
  isTokenRefreshInProgress.current = false
71
86
  } catch {
@@ -21,23 +21,31 @@ export interface useDocumentPreviewOptions extends DocumentHandle {
21
21
  * @category Types
22
22
  */
23
23
  export interface useDocumentPreviewResults {
24
- /** The results of resolving the document’s preview values */
24
+ /** The results of inferring the document’s preview values */
25
25
  data: PreviewValue
26
- /** True when preview values are being refreshed */
26
+ /** True when inferred preview values are being refreshed */
27
27
  isPending: boolean
28
28
  }
29
29
 
30
30
  /**
31
31
  * @public
32
32
  *
33
- * Returns the preview values of a document (specified via a `DocumentHandle`),
33
+ * Attempts to infer preview values of a document (specified via a `DocumentHandle`),
34
34
  * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
35
35
  * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
36
36
  * resolution will only occur if the `ref` is intersecting the current viewport.
37
37
  *
38
+ * See remarks below for futher information.
39
+ *
40
+ * @remarks
41
+ * Values returned by this hook may not be as expected. It is currently unable to read preview values as defined in your schema;
42
+ * instead, it attempts to infer these preview values by checking against a basic set of potential fields on your document.
43
+ * We are anticipating being able to significantly improve this hook’s functionality and output in a future release.
44
+ * For now, we recommend using {@link useDocumentProjection} for rendering individual document fields (or projections of those fields).
45
+ *
38
46
  * @category Documents
39
- * @param options - The document handle for the document you want to resolve preview values for, and an optional ref
40
- * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
47
+ * @param options - The document handle for the document you want to infer preview values for, and an optional ref
48
+ * @returns The inferred values for the given document and a boolean to indicate whether the resolution is pending
41
49
  *
42
50
  * @example Combining with useDocuments to render a collection of document previews
43
51
  * ```