File tree Expand file tree Collapse file tree 6 files changed +37
-5
lines changed
Expand file tree Collapse file tree 6 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " next-sanity " : minor
3+ ---
4+
5+ Add ` resolvePerspectiveFromCookies ` export
Original file line number Diff line number Diff line change 4242 "./live/client-components/live" : " ./src/live/client-components/live/index.ts" ,
4343 "./live/client-components/live-stream" : " ./src/live/client-components/live-stream/index.ts" ,
4444 "./live/server-actions" : " ./src/live/server-actions/index.ts" ,
45- "./package.json" : " ./package.json" ,
4645 "./studio" : " ./src/studio/index.ts" ,
4746 "./studio/client-component" : " ./src/studio/client-component/index.ts" ,
4847 "./visual-editing" : " ./src/visual-editing/index.ts" ,
4948 "./visual-editing/client-component" : " ./src/visual-editing/client-component/index.ts" ,
5049 "./visual-editing/server-actions" : " ./src/visual-editing/server-actions/index.ts" ,
51- "./webhook" : " ./src/webhook/index.ts"
50+ "./webhook" : " ./src/webhook/index.ts" ,
51+ "./package.json" : " ./package.json"
5252 },
5353 "module" : " ./dist/index.js" ,
5454 "types" : " ./dist/index.d.ts" ,
Original file line number Diff line number Diff line change 99 type DefinedSanityLiveProps ,
1010 type SanityFetchOptions ,
1111 defineLive ,
12- resolvePerspectiveFromCookies ,
1312} from './experimental/live'
13+
14+ export { resolvePerspectiveFromCookies } from '#live/resolvePerspectiveFromCookies'
Original file line number Diff line number Diff line change @@ -11,3 +11,5 @@ export {
1111 type DefinedSanityLiveStreamType ,
1212 defineLive ,
1313} from './live/defineLive'
14+
15+ export { resolvePerspectiveFromCookies } from '#live/resolvePerspectiveFromCookies'
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export function defineLive(_config: DefineSanityLiveOptions): {
2121 SanityLive : React . ComponentType < DefinedSanityLiveProps >
2222 SanityLiveStream : DefinedSanityLiveStreamType
2323} {
24- throw new Error ( ' defineLive can only be used in React Server Components' )
24+ throw new Error ( ` defineLive can't be imported by a client component` )
2525}
2626
2727/**
@@ -33,3 +33,13 @@ export type {
3333 DefinedSanityLiveProps ,
3434 DefinedSanityLiveStreamType ,
3535}
36+
37+ import type { ResolvePerspectiveFromCookies } from '#live/resolvePerspectiveFromCookies'
38+
39+ /**
40+ * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from "next-sanity/draft-mode"`
41+ * @public
42+ */
43+ export const resolvePerspectiveFromCookies : ResolvePerspectiveFromCookies = async ( ) => {
44+ throw new Error ( `resolvePerspectiveFromCookies can't be imported by a client component` )
45+ }
Original file line number Diff line number Diff line change @@ -4,11 +4,25 @@ import type {cookies} from 'next/headers'
44import { sanitizePerspective } from '#live/sanitizePerspective'
55import { perspectiveCookieName } from '@sanity/preview-url-secret/constants'
66
7+ export type ResolvePerspectiveFromCookies = ( options : {
8+ /**
9+ * You must await the cookies() function from next/headers
10+ * and pass it here.
11+ * Example:
12+ * ```ts
13+ * import { cookies } from 'next/headers'
14+ *
15+ * const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
16+ * ```
17+ */
18+ cookies : Awaited < ReturnType < typeof cookies > >
19+ } ) => Promise < Exclude < ClientPerspective , 'raw' > >
20+
721/**
822 * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from "next-sanity/draft-mode"`
923 * @public
1024 */
11- export async function resolvePerspectiveFromCookies ( {
25+ export const resolvePerspectiveFromCookies = async function resolvePerspectiveFromCookies ( {
1226 cookies : jar ,
1327} : {
1428 cookies : Awaited < ReturnType < typeof cookies > >
You can’t perform that action at this time.
0 commit comments