next-sanity 12.4.1 → 12.4.3

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.
@@ -12,16 +12,8 @@ const RefreshOnFocus = dynamic(() => import("./RefreshOnFocus.js"));
12
12
  const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
13
13
  const RefreshOnInterval = dynamic(() => import("./RefreshOnInterval.js"));
14
14
  const RefreshOnReconnect = dynamic(() => import("./RefreshOnReconnect.js"));
15
- function handleError(error) {
16
- if (isCorsOriginError(error)) console.warn(`Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`, error.addOriginUrl && `Add it here:`, error.addOriginUrl?.toString());
17
- else console.error(error);
18
- }
19
- function handleOnGoAway(event, intervalOnGoAway) {
20
- if (intervalOnGoAway) console.warn("Sanity Live connection closed, switching to long polling set to a interval of", intervalOnGoAway / 1e3, "seconds and the server gave this reason:", event.reason);
21
- else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
22
- }
23
15
  function SanityLive(props) {
24
- const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix, draftModeEnabled, draftModePerspective, refreshOnMount = false, refreshOnFocus = draftModeEnabled ? false : typeof window === "undefined" ? true : window.self === window.top, refreshOnReconnect = true, intervalOnGoAway = 3e4, requestTag = "next-loader.live", onError = handleError, onGoAway = handleOnGoAway, revalidateSyncTags: revalidateSyncTags$1 = revalidateSyncTags, waitFor } = props;
16
+ const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix, draftModeEnabled, draftModePerspective, requestTag = "next-loader.live", waitFor, revalidateSyncTags: revalidateSyncTags$1 = revalidateSyncTags, onError = handleError, intervalOnGoAway = 3e4, onGoAway = handleOnGoAway, refreshOnMount = false, refreshOnFocus = draftModeEnabled ? false : typeof window === "undefined" ? true : window.self === window.top, refreshOnReconnect = true } = props;
25
17
  const client = useMemo(() => createClient({
26
18
  projectId,
27
19
  dataset,
@@ -152,6 +144,14 @@ function SanityLive(props) {
152
144
  ] });
153
145
  }
154
146
  SanityLive.displayName = "SanityLiveClientComponent";
147
+ function handleError(error) {
148
+ if (isCorsOriginError(error)) console.warn(`Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`, error.addOriginUrl && `Add it here:`, error.addOriginUrl?.toString());
149
+ else console.error(error);
150
+ }
151
+ function handleOnGoAway(event, intervalOnGoAway) {
152
+ if (intervalOnGoAway) console.warn("Sanity Live connection closed, switching to long polling set to a interval of", intervalOnGoAway / 1e3, "seconds and the server gave this reason:", event.reason);
153
+ else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
154
+ }
155
155
  export { SanityLive as default };
156
156
 
157
157
  //# sourceMappingURL=SanityLive.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SanityLive.js","names":["defaultRevalidateSyncTags","revalidateSyncTags"],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {\n createClient,\n type ClientPerspective,\n type InitializedClientConfig,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {isMaybePresentation, isMaybePreviewWindow} from '@sanity/presentation-comlink'\nimport {revalidateSyncTags as defaultRevalidateSyncTags} from 'next-sanity/live/server-actions'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useRef, useState, useEffectEvent, startTransition} from 'react'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\n\nimport {setEnvironment, setPerspective} from '../hooks/context'\n\nconst PresentationComlink = dynamic(() => import('./PresentationComlink'))\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\n/**\n * @public\n */\nexport interface SanityLiveProps extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {\n draftModeEnabled: boolean\n draftModePerspective?: ClientPerspective\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string | undefined\n onError?: (error: unknown) => void\n intervalOnGoAway?: number | false\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | 'refresh'>\n waitFor?: 'function'\n}\n\nfunction handleError(error: unknown) {\n if (isCorsOriginError(error)) {\n console.warn(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`,\n error.addOriginUrl && `Add it here:`,\n error.addOriginUrl?.toString(),\n )\n } else {\n console.error(error)\n }\n}\n\nfunction handleOnGoAway(event: LiveEventGoAway, intervalOnGoAway: number | false) {\n if (intervalOnGoAway) {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n intervalOnGoAway / 1000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n } else {\n console.error(\n 'Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:',\n event.reason,\n )\n }\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n token,\n requestTagPrefix,\n draftModeEnabled,\n draftModePerspective,\n refreshOnMount = false,\n refreshOnFocus = draftModeEnabled\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag = 'next-loader.live',\n onError = handleError,\n onGoAway = handleOnGoAway,\n revalidateSyncTags = defaultRevalidateSyncTags,\n waitFor,\n } = props\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n /**\n * 1. Handle Live Events and call revalidateTag or router.refresh when needed\n */\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n if (process.env.NODE_ENV !== 'production' && event.type === 'welcome') {\n // oxlint-disable-next-line no-console\n console.info(\n 'Sanity is live with',\n token\n ? 'automatic revalidation for draft content changes as well as published content'\n : draftModeEnabled\n ? 'automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool.'\n : 'automatic revalidation of published content',\n )\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n } else if (event.type === 'message') {\n if (waitFor === 'function') {\n // Cache is already revalidated by the Sanity Function, just refresh the router\n startTransition(() => router.refresh())\n } else {\n void revalidateSyncTags(event.tags).then((result) => {\n if (result === 'refresh') startTransition(() => router.refresh())\n })\n }\n } else if (event.type === 'restart' || event.type === 'reconnect') {\n // Disable long polling when restart/reconnect event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n // @TODO add support for `onRestart` and `onReconnect` events so this can be customized\n startTransition(() => router.refresh())\n } else if (event.type === 'goaway') {\n onGoAway(event, intervalOnGoAway)\n startTransition(() => setRefreshOnInterval(intervalOnGoAway))\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: !!token, tag: requestTag, waitFor})\n .subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n // console.error('What?', err)\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token, waitFor])\n\n /**\n * 2. Notify what perspective we're in, when in Draft Mode\n */\n useEffect(() => {\n if (draftModeEnabled && draftModePerspective) {\n setPerspective(draftModePerspective)\n } else {\n setPerspective('unknown')\n }\n }, [draftModeEnabled, draftModePerspective])\n\n const [loadComlink, setLoadComlink] = useState(false)\n /**\n * 3. Notify what environment we're in, when in Draft Mode\n */\n useEffect(() => {\n // If we might be in Presentation Tool, then skip detecting here as it's handled later\n if (isMaybePresentation()) return\n\n // If we're definitely not in Presentation Tool, then we can set the environment as stand-alone live preview\n // if we have both a browser token, and draft mode is enabled\n if (draftModeEnabled && token) {\n setEnvironment('live')\n return\n }\n // If we're in draft mode, but don't have a browser token, then we're in static mode\n // which means that published content is still live, but draft changes likely need manual refresh\n if (draftModeEnabled) {\n setEnvironment('static')\n return\n }\n\n // Fallback to `unknown` otherwise, as we simply don't know how it's setup\n setEnvironment('unknown')\n return\n }, [draftModeEnabled, token])\n\n /**\n * 4. If Presentation Tool is detected, load up the comlink and integrate with it\n */\n useEffect(() => {\n if (!isMaybePresentation()) return\n const controller = new AbortController()\n // Wait for a while to see if Presentation Tool is detected, before assuming the env to be stand-alone live preview\n const timeout = setTimeout(() => setEnvironment('live'), 3_000)\n window.addEventListener(\n 'message',\n ({data}: MessageEvent<unknown>) => {\n if (\n data &&\n typeof data === 'object' &&\n 'domain' in data &&\n data.domain === 'sanity/channels' &&\n 'from' in data &&\n data.from === 'presentation'\n ) {\n clearTimeout(timeout)\n setEnvironment(isMaybePreviewWindow() ? 'presentation-window' : 'presentation-iframe')\n setLoadComlink(true)\n controller.abort()\n }\n },\n {signal: controller.signal},\n )\n return () => {\n clearTimeout(timeout)\n controller.abort()\n }\n }, [])\n\n /**\n * 5. Warn if draft mode is being disabled\n * @TODO move logic into PresentationComlink, or maybe VisualEditing?\n */\n const draftModeEnabledWarnRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n useEffect(() => {\n if (!draftModeEnabled) return\n clearTimeout(draftModeEnabledWarnRef.current)\n return () => {\n draftModeEnabledWarnRef.current = setTimeout(() => {\n console.warn('Sanity Live: Draft mode was enabled, but is now being disabled')\n })\n }\n }, [draftModeEnabled])\n\n return (\n <>\n {draftModeEnabled && loadComlink && (\n <PresentationComlink\n projectId={projectId!}\n dataset={dataset!}\n draftModeEnabled={draftModeEnabled}\n draftModePerspective={draftModePerspective!}\n />\n )}\n {!draftModeEnabled && refreshOnMount && <RefreshOnMount />}\n {refreshOnInterval && Number.isFinite(refreshOnInterval) && refreshOnInterval > 0 && (\n <RefreshOnInterval interval={refreshOnInterval} />\n )}\n {!draftModeEnabled && refreshOnFocus && <RefreshOnFocus />}\n {!draftModeEnabled && refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;;;;;AAkBA,MAAM,sBAAsB,cAAc,OAAO,4BAAyB;AAC1E,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,oBAAoB,cAAc,OAAO,0BAAuB;AACtE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;AA4BxE,SAAS,YAAY,OAAgB;AACnC,KAAI,kBAAkB,MAAM,CAC1B,SAAQ,KACN,8EAA8E,OAAO,OAAO,yEAC5F,MAAM,gBAAgB,gBACtB,MAAM,cAAc,UAAU,CAC/B;KAED,SAAQ,MAAM,MAAM;;AAIxB,SAAS,eAAe,OAAwB,kBAAkC;AAChF,KAAI,iBACF,SAAQ,KACN,iFACA,mBAAmB,KACnB,4CACA,MAAM,OACP;KAED,SAAQ,MACN,mGACA,MAAM,OACP;;AAIL,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,WACA,SACA,SACA,YACA,oBACA,OACA,kBACA,kBACA,sBACA,iBAAiB,OACjB,iBAAiB,mBACb,QACA,OAAO,WAAW,cAChB,OACA,OAAO,SAAS,OAAO,KAC7B,qBAAqB,MACrB,mBAAmB,KACnB,aAAa,oBACb,UAAU,aACV,WAAW,gBACX,oBAAA,uBAAqBA,oBACrB,YACE;CAEJ,MAAM,SAAS,cAEX,aAAa;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E,EAAA,CAAA;;AAIP,WAAW,cAAc"}
1
+ {"version":3,"file":"SanityLive.js","names":["defaultRevalidateSyncTags","revalidateSyncTags"],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {\n createClient,\n type ClientPerspective,\n type InitializedClientConfig,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {isMaybePresentation, isMaybePreviewWindow} from '@sanity/presentation-comlink'\nimport {revalidateSyncTags as defaultRevalidateSyncTags} from 'next-sanity/live/server-actions'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useRef, useState, useEffectEvent, startTransition} from 'react'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\n\nimport {setEnvironment, setPerspective} from '../hooks/context'\n\nconst PresentationComlink = dynamic(() => import('./PresentationComlink'))\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\nexport interface SanityLiveProps extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {\n draftModeEnabled: boolean\n draftModePerspective?: ClientPerspective\n requestTag: string | undefined\n waitFor?: 'function'\n\n revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | 'refresh'>\n onError?: (error: unknown) => void\n intervalOnGoAway?: number | false\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n token,\n requestTagPrefix,\n draftModeEnabled,\n draftModePerspective,\n requestTag = 'next-loader.live',\n waitFor,\n\n revalidateSyncTags = defaultRevalidateSyncTags,\n onError = handleError,\n intervalOnGoAway = 30_000,\n onGoAway = handleOnGoAway,\n\n refreshOnMount = false,\n refreshOnFocus = draftModeEnabled\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n } = props\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n /**\n * 1. Handle Live Events and call revalidateTag or router.refresh when needed\n */\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n if (process.env.NODE_ENV !== 'production' && event.type === 'welcome') {\n // oxlint-disable-next-line no-console\n console.info(\n 'Sanity is live with',\n token\n ? 'automatic revalidation for draft content changes as well as published content'\n : draftModeEnabled\n ? 'automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool.'\n : 'automatic revalidation of published content',\n )\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n } else if (event.type === 'message') {\n if (waitFor === 'function') {\n // Cache is already revalidated by the Sanity Function, just refresh the router\n startTransition(() => router.refresh())\n } else {\n void revalidateSyncTags(event.tags).then((result) => {\n if (result === 'refresh') startTransition(() => router.refresh())\n })\n }\n } else if (event.type === 'restart' || event.type === 'reconnect') {\n // Disable long polling when restart/reconnect event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n // @TODO add support for `onRestart` and `onReconnect` events so this can be customized\n startTransition(() => router.refresh())\n } else if (event.type === 'goaway') {\n onGoAway(event, intervalOnGoAway)\n startTransition(() => setRefreshOnInterval(intervalOnGoAway))\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: !!token, tag: requestTag, waitFor})\n .subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token, waitFor])\n\n /**\n * 2. Notify what perspective we're in, when in Draft Mode\n */\n useEffect(() => {\n if (draftModeEnabled && draftModePerspective) {\n setPerspective(draftModePerspective)\n } else {\n setPerspective('unknown')\n }\n }, [draftModeEnabled, draftModePerspective])\n\n const [loadComlink, setLoadComlink] = useState(false)\n /**\n * 3. Notify what environment we're in, when in Draft Mode\n */\n useEffect(() => {\n // If we might be in Presentation Tool, then skip detecting here as it's handled later\n if (isMaybePresentation()) return\n\n // If we're definitely not in Presentation Tool, then we can set the environment as stand-alone live preview\n // if we have both a browser token, and draft mode is enabled\n if (draftModeEnabled && token) {\n setEnvironment('live')\n return\n }\n // If we're in draft mode, but don't have a browser token, then we're in static mode\n // which means that published content is still live, but draft changes likely need manual refresh\n if (draftModeEnabled) {\n setEnvironment('static')\n return\n }\n\n // Fallback to `unknown` otherwise, as we simply don't know how it's setup\n setEnvironment('unknown')\n return\n }, [draftModeEnabled, token])\n\n /**\n * 4. If Presentation Tool is detected, load up the comlink and integrate with it\n */\n useEffect(() => {\n if (!isMaybePresentation()) return\n const controller = new AbortController()\n // Wait for a while to see if Presentation Tool is detected, before assuming the env to be stand-alone live preview\n const timeout = setTimeout(() => setEnvironment('live'), 3_000)\n window.addEventListener(\n 'message',\n ({data}: MessageEvent<unknown>) => {\n if (\n data &&\n typeof data === 'object' &&\n 'domain' in data &&\n data.domain === 'sanity/channels' &&\n 'from' in data &&\n data.from === 'presentation'\n ) {\n clearTimeout(timeout)\n setEnvironment(isMaybePreviewWindow() ? 'presentation-window' : 'presentation-iframe')\n setLoadComlink(true)\n controller.abort()\n }\n },\n {signal: controller.signal},\n )\n return () => {\n clearTimeout(timeout)\n controller.abort()\n }\n }, [])\n\n /**\n * 5. Warn if draft mode is being disabled\n * @TODO move logic into PresentationComlink, or maybe VisualEditing?\n */\n const draftModeEnabledWarnRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n useEffect(() => {\n if (!draftModeEnabled) return\n clearTimeout(draftModeEnabledWarnRef.current)\n return () => {\n draftModeEnabledWarnRef.current = setTimeout(() => {\n console.warn('Sanity Live: Draft mode was enabled, but is now being disabled')\n })\n }\n }, [draftModeEnabled])\n\n return (\n <>\n {draftModeEnabled && loadComlink && (\n <PresentationComlink\n projectId={projectId!}\n dataset={dataset!}\n draftModeEnabled={draftModeEnabled}\n draftModePerspective={draftModePerspective!}\n />\n )}\n {!draftModeEnabled && refreshOnMount && <RefreshOnMount />}\n {refreshOnInterval && Number.isFinite(refreshOnInterval) && refreshOnInterval > 0 && (\n <RefreshOnInterval interval={refreshOnInterval} />\n )}\n {!draftModeEnabled && refreshOnFocus && <RefreshOnFocus />}\n {!draftModeEnabled && refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n\nfunction handleError(error: unknown) {\n if (isCorsOriginError(error)) {\n console.warn(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`,\n error.addOriginUrl && `Add it here:`,\n error.addOriginUrl?.toString(),\n )\n } else {\n console.error(error)\n }\n}\n\nfunction handleOnGoAway(event: LiveEventGoAway, intervalOnGoAway: number | false) {\n if (intervalOnGoAway) {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n intervalOnGoAway / 1000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n } else {\n console.error(\n 'Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:',\n event.reason,\n )\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,MAAM,sBAAsB,cAAc,OAAO,4BAAyB;AAC1E,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAo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iB,CAAC;AAEtB,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,oBAAoB,eACnB,oBAAC,qBAAD;GACa;GACF;GACS;GACI;GACtB,CAAA;EAEH,CAAC,oBAAoB,kBAAkB,oBAAC,gBAAD,EAAkB,CAAA;EACzD,qBAAqB,OAAO,SAAS,kBAAkB,IAAI,oBAAoB,KAC9E,oBAAC,mBAAD,EAAmB,UAAU,mBAAqB,CAAA;EAEnD,CAAC,oBAAoB,kBAAkB,oBAAC,gBAAD,EAAkB,CAAA;EACzD,CAAC,oBAAoB,sBAAsB,oBAAC,oBAAD,EAAsB,CAAA;EACjE,EAAA,CAAA;;AAIP,WAAW,cAAc;AAIzB,SAAS,YAAY,OAAgB;AACnC,KAAI,kBAAkB,MAAM,CAC1B,SAAQ,KACN,8EAA8E,OAAO,OAAO,yEAC5F,MAAM,gBAAgB,gBACtB,MAAM,cAAc,UAAU,CAC/B;KAED,SAAQ,MAAM,MAAM;;AAIxB,SAAS,eAAe,OAAwB,kBAAkC;AAChF,KAAI,iBACF,SAAQ,KACN,iFACA,mBAAmB,KACnB,4CACA,MAAM,OACP;KAED,SAAQ,MACN,mGACA,MAAM,OACP"}
@@ -1,22 +1,19 @@
1
1
  import { ClientPerspective, InitializedClientConfig, LiveEventGoAway, SyncTag } from "@sanity/client";
2
- /**
3
- * @public
4
- */
5
2
  interface SanityLiveProps extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {
6
3
  draftModeEnabled: boolean;
7
4
  draftModePerspective?: ClientPerspective;
8
- refreshOnMount?: boolean;
9
- refreshOnFocus?: boolean;
10
- refreshOnReconnect?: boolean;
11
5
  requestTag: string | undefined;
6
+ waitFor?: "function";
7
+ revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | "refresh">;
12
8
  onError?: (error: unknown) => void;
13
9
  intervalOnGoAway?: number | false;
14
10
  onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
15
- revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | "refresh">;
16
- waitFor?: "function";
11
+ refreshOnMount?: boolean;
12
+ refreshOnFocus?: boolean;
13
+ refreshOnReconnect?: boolean;
17
14
  }
18
15
  /**
19
- * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
16
+ * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
20
17
  */
21
18
  declare const SanityLive: React.ComponentType<SanityLiveProps>;
22
19
  export { SanityLive };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"mappings":";;AA2BA;;UAAiB,eAAA,SAAwB,IAAA,CACvC,uBAAA;EASA,gBAAA;EACA,oBAAA,GAAuB,iBAAA;EACvB,cAAA;EACA,cAAA;EACA,kBAAA;EACA,UAAA;EACA,OAAA,IAAW,KAAA;EACX,gBAAA;EACA,QAAA,IAAY,KAAA,EAAO,eAAA,EAAiB,gBAAA;EACpC,kBAAA,IAAsB,IAAA,EAAM,OAAA,OAAc,OAAA;EAC1C,OAAA;AAAA;;AApBF;;cCnBa,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,eAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"mappings":";UAwBiB,eAAA,SAAwB,IAAA,CACvC,uBAAA;EASA,gBAAA;EACA,oBAAA,GAAuB,iBAAA;EACvB,UAAA;EACA,OAAA;EAEA,kBAAA,IAAsB,IAAA,EAAM,OAAA,OAAc,OAAA;EAC1C,OAAA,IAAW,KAAA;EACX,gBAAA;EACA,QAAA,IAAY,KAAA,EAAO,eAAA,EAAiB,gBAAA;EAEpC,cAAA;EACA,cAAA;EACA,kBAAA;AAAA;;AAtBF;;cChBa,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,eAAA"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import dynamic from "next/dynamic";
3
3
  /**
4
- * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
4
+ * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
5
5
  */
6
6
  const SanityLive = dynamic(() => import("../../SanityLive.js"), { ssr: false });
7
7
  export { SanityLive };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\n/**\n * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;;;;AAQA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,OAAM,CACb"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\n/**\n * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;;;;AAQA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,OAAM,CACb"}
@@ -1,5 +1,11 @@
1
1
  import { ClientPerspective, SyncTag } from "@sanity/client";
2
+ /**
3
+ * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
4
+ */
2
5
  declare function revalidateSyncTags(tags: SyncTag[]): Promise<void>;
6
+ /**
7
+ * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
8
+ */
3
9
  declare function setPerspectiveCookie(perspective: ClientPerspective): Promise<void>;
4
10
  export { revalidateSyncTags, setPerspectiveCookie };
5
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/server-actions/index.ts"],"mappings":";iBASsB,kBAAA,CAAmB,IAAA,EAAM,OAAA,KAAY,OAAA;AAAA,iBAwBrC,oBAAA,CAAqB,WAAA,EAAa,iBAAA,GAAoB,OAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/server-actions/index.ts"],"mappings":";;AAYA;;iBAAsB,kBAAA,CAAmB,IAAA,EAAM,OAAA,KAAY,OAAA;;;;iBA2BrC,oBAAA,CAAqB,WAAA,EAAa,iBAAA,GAAoB,OAAA"}
@@ -3,6 +3,9 @@ import { t as sanitizePerspective } from "../../sanitizePerspective.js";
3
3
  import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
4
4
  import { cookies, draftMode } from "next/headers";
5
5
  import { revalidateTag, updateTag } from "next/cache";
6
+ /**
7
+ * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
8
+ */
6
9
  async function revalidateSyncTags(tags) {
7
10
  const { isEnabled: isDraftMode } = await draftMode();
8
11
  if (!isDraftMode) revalidateTag("sanity:fetch-sync-tags", "max");
@@ -15,6 +18,9 @@ async function revalidateSyncTags(tags) {
15
18
  }
16
19
  console.log(`<SanityLive /> ${isDraftMode ? `revalidated tags: ${logTags.join(", ")} with cache profile "max" ` : `updated tags: ${logTags.join(", ")} and revalidated tag: "sanity:fetch-sync-tags" with cache profile "max"`}`);
17
20
  }
21
+ /**
22
+ * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
23
+ */
18
24
  async function setPerspectiveCookie(perspective) {
19
25
  if (!(await draftMode()).isEnabled) return;
20
26
  const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective, SyncTag} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {revalidateTag, updateTag} from 'next/cache'\nimport {cookies, draftMode} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\nexport async function revalidateSyncTags(tags: SyncTag[]): Promise<void> {\n const {isEnabled: isDraftMode} = await draftMode()\n\n if (!isDraftMode) {\n revalidateTag('sanity:fetch-sync-tags', 'max')\n }\n\n const logTags: string[] = []\n for (const _tag of tags) {\n const tag = `sanity:${_tag}`\n if (isDraftMode) {\n revalidateTag(tag, 'max')\n } else {\n updateTag(tag)\n }\n logTags.push(tag)\n }\n\n // oxlint-disable-next-line no-console\n console.log(\n `<SanityLive /> ${isDraftMode ? `revalidated tags: ${logTags.join(', ')} with cache profile \"max\" ` : `updated tags: ${logTags.join(', ')} and revalidated tag: \"sanity:fetch-sync-tags\" with cache profile \"max\"`}`,\n )\n}\n\nexport async function setPerspectiveCookie(perspective: ClientPerspective): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // throw new Error('Draft mode is not enabled, setting perspective cookie is not allowed')\n return\n }\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (perspective !== sanitizedPerspective) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n ;(await cookies()).set(\n perspectiveCookieName,\n Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(',') : sanitizedPerspective,\n {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n },\n )\n}\n"],"mappings":";;;;;AASA,eAAsB,mBAAmB,MAAgC;CACvE,MAAM,EAAC,WAAW,gBAAe,MAAM,WAAW;AAElD,KAAI,CAAC,YACH,eAAc,0BAA0B,MAAM;CAGhD,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,MAAM,UAAU;AACtB,MAAI,YACF,eAAc,KAAK,MAAM;MAEzB,WAAU,IAAI;AAEhB,UAAQ,KAAK,IAAI;;AAInB,SAAQ,IACN,kBAAkB,cAAc,qBAAqB,QAAQ,KAAK,KAAK,CAAC,8BAA8B,iBAAiB,QAAQ,KAAK,KAAK,CAAC,2EAC3I;;AAGH,eAAsB,qBAAqB,aAA+C;AACxF,KAAI,EAAE,MAAM,WAAW,EAAE,UAEvB;CAEF,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KAAI,gBAAgB,qBAClB,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;AAG7D,EAAC,MAAM,SAAS,EAAE,IACjB,uBACA,MAAM,QAAQ,qBAAqB,GAAG,qBAAqB,KAAK,IAAI,GAAG,sBACvE;EACE,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective, SyncTag} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {revalidateTag, updateTag} from 'next/cache'\nimport {cookies, draftMode} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function revalidateSyncTags(tags: SyncTag[]): Promise<void> {\n const {isEnabled: isDraftMode} = await draftMode()\n\n if (!isDraftMode) {\n revalidateTag('sanity:fetch-sync-tags', 'max')\n }\n\n const logTags: string[] = []\n for (const _tag of tags) {\n const tag = `sanity:${_tag}`\n if (isDraftMode) {\n revalidateTag(tag, 'max')\n } else {\n updateTag(tag)\n }\n logTags.push(tag)\n }\n\n // oxlint-disable-next-line no-console\n console.log(\n `<SanityLive /> ${isDraftMode ? `revalidated tags: ${logTags.join(', ')} with cache profile \"max\" ` : `updated tags: ${logTags.join(', ')} and revalidated tag: \"sanity:fetch-sync-tags\" with cache profile \"max\"`}`,\n )\n}\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function setPerspectiveCookie(perspective: ClientPerspective): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // throw new Error('Draft mode is not enabled, setting perspective cookie is not allowed')\n return\n }\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (perspective !== sanitizedPerspective) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n ;(await cookies()).set(\n perspectiveCookieName,\n Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(',') : sanitizedPerspective,\n {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n },\n )\n}\n"],"mappings":";;;;;;;;AAYA,eAAsB,mBAAmB,MAAgC;CACvE,MAAM,EAAC,WAAW,gBAAe,MAAM,WAAW;AAElD,KAAI,CAAC,YACH,eAAc,0BAA0B,MAAM;CAGhD,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,MAAM,UAAU;AACtB,MAAI,YACF,eAAc,KAAK,MAAM;MAEzB,WAAU,IAAI;AAEhB,UAAQ,KAAK,IAAI;;AAInB,SAAQ,IACN,kBAAkB,cAAc,qBAAqB,QAAQ,KAAK,KAAK,CAAC,8BAA8B,iBAAiB,QAAQ,KAAK,KAAK,CAAC,2EAC3I;;;;;AAMH,eAAsB,qBAAqB,aAA+C;AACxF,KAAI,EAAE,MAAM,WAAW,EAAE,UAEvB;CAEF,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KAAI,gBAAgB,qBAClB,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;AAG7D,EAAC,MAAM,SAAS,EAAE,IACjB,uBACA,MAAM,QAAQ,qBAAqB,GAAG,qBAAqB,KAAK,IAAI,GAAG,sBACvE;EACE,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "12.4.1",
3
+ "version": "12.4.3",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "live",
@@ -57,7 +57,7 @@
57
57
  "./package.json": "./package.json"
58
58
  },
59
59
  "dependencies": {
60
- "@portabletext/react": "^6.0.3",
60
+ "@portabletext/react": "^6.2.0",
61
61
  "@sanity/client": "^7.22.0",
62
62
  "@sanity/comlink": "^4.0.1",
63
63
  "@sanity/presentation-comlink": "^2.0.1",
@@ -65,7 +65,7 @@
65
65
  "@sanity/visual-editing": "^5.3.4",
66
66
  "@sanity/webhook": "^4.0.4",
67
67
  "dequal": "^2.0.3",
68
- "groq": "^5.23.0",
68
+ "groq": "^5.24.0",
69
69
  "history": "^5.3.0"
70
70
  },
71
71
  "devDependencies": {
@@ -77,7 +77,7 @@
77
77
  "@vitejs/plugin-react": "^6.0.1",
78
78
  "@vitest/coverage-v8": "^4.1.5",
79
79
  "js-yaml": "^4.1.1",
80
- "next": "16.3.0-canary.10",
80
+ "next": "16.3.0-canary.11",
81
81
  "publint": "^0.3.18",
82
82
  "react": "^19.2.5",
83
83
  "react-dom": "^19.2.5",
@@ -94,7 +94,7 @@
94
94
  "next": "^16.0.0-0",
95
95
  "react": "^19.2.3",
96
96
  "react-dom": "^19.2.3",
97
- "sanity": "^5.23.0",
97
+ "sanity": "^5.24.0",
98
98
  "styled-components": "^6.1"
99
99
  },
100
100
  "engines": {