@sanity/sdk-react 2.16.0 → 2.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/sdk-react",
3
- "version": "2.16.0",
3
+ "version": "2.18.0",
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": "^1.0.0",
52
52
  "react-error-boundary": "^6.1.2",
53
53
  "rxjs": "^7.8.2",
54
- "@sanity/sdk": "2.16.0"
54
+ "@sanity/sdk": "2.18.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@sanity/browserslist-config": "^1.0.5",
@@ -59,14 +59,14 @@
59
59
  "@sanity/pkg-utils": "^10.5.8",
60
60
  "@testing-library/jest-dom": "^6.9.1",
61
61
  "@testing-library/react": "^16.3.2",
62
- "@types/node": "^24.12.4",
62
+ "@types/node": "^24.13.3",
63
63
  "@types/react": "^19.2.17",
64
64
  "@types/react-dom": "^19.2.3",
65
65
  "@vitejs/plugin-react": "^6.0.3",
66
66
  "@vitest/coverage-v8": "^4.1.10",
67
67
  "babel-plugin-react-compiler": "^1.0.0",
68
68
  "eslint": "^10.6.0",
69
- "groq-js": "^1.30.2",
69
+ "groq-js": "^1.30.3",
70
70
  "jsdom": "^29.1.1",
71
71
  "oxfmt": "^0.58.0",
72
72
  "react": "^19.2.7",
@@ -75,11 +75,11 @@
75
75
  "typescript": "^6.0.3",
76
76
  "vite": "^8.1.4",
77
77
  "vitest": "^4.1.10",
78
+ "@repo/config-eslint": "0.0.0",
78
79
  "@repo/config-test": "0.0.1",
79
- "@repo/tsconfig": "0.0.1",
80
- "@repo/package.config": "0.0.1",
81
80
  "@repo/package.bundle": "3.82.0",
82
- "@repo/config-eslint": "0.0.0"
81
+ "@repo/tsconfig": "0.0.1",
82
+ "@repo/package.config": "0.0.1"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "react": "^18.0.0 || ^19.0.0",
@@ -101,6 +101,37 @@ describe('useWindowTitle', () => {
101
101
  })
102
102
  })
103
103
 
104
+ it('should fall back to the iframe title when the dashboard resource has no title', async () => {
105
+ document.title = 'Local App'
106
+
107
+ const mockFetch = vi.fn().mockResolvedValue(
108
+ createContextResponse({
109
+ type: 'application',
110
+ title: '',
111
+ manifest: null,
112
+ activeDeployment: null,
113
+ }),
114
+ )
115
+ vi.mocked(useWindowConnection).mockReturnValue({
116
+ fetch: mockFetch,
117
+ sendMessage: vi.fn(),
118
+ })
119
+
120
+ const {rerender} = renderHook(({viewTitle}) => useWindowTitle(viewTitle), {
121
+ initialProps: {viewTitle: 'Teams'},
122
+ })
123
+
124
+ await waitFor(() => {
125
+ expect(document.title).toBe('Teams | Local App')
126
+ })
127
+
128
+ rerender({viewTitle: 'Week 10'})
129
+
130
+ await waitFor(() => {
131
+ expect(document.title).toBe('Week 10 | Local App')
132
+ })
133
+ })
134
+
104
135
  it('should prepend view title when provided', async () => {
105
136
  const mockFetch = vi.fn().mockResolvedValue(
106
137
  createContextResponse({
@@ -23,7 +23,7 @@ interface ContextResponse {
23
23
  }
24
24
 
25
25
  function resolveAppTitle(resource: ContextResource): string | undefined {
26
- return resource.manifest?.title ?? resource.activeDeployment?.manifest?.title ?? resource.title
26
+ return resource.manifest?.title || resource.activeDeployment?.manifest?.title || resource.title
27
27
  }
28
28
 
29
29
  /**
@@ -81,7 +81,9 @@ export function useWindowTitle(viewTitle?: string): void {
81
81
  async function fetchAppTitle(signal: AbortSignal) {
82
82
  try {
83
83
  const data = await fetch<ContextResponse>('dashboard/v1/context', undefined, {signal})
84
- const title = resolveAppTitle(data.context.resource)
84
+ // Local development resources do not have a registered title or deployment manifest.
85
+ // In that case, use the title rendered into the iframe HTML by the Sanity CLI.
86
+ const title = resolveAppTitle(data.context.resource) || document.title
85
87
  if (title) {
86
88
  setAppTitle(title)
87
89
  }