next-sanity 13.0.0-cache-components.28 → 13.0.0-cache-components.29
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/dist/SanityLive.js
CHANGED
|
@@ -37,25 +37,25 @@ function SanityLive(props) {
|
|
|
37
37
|
if (onError) onError(error, actionContext);
|
|
38
38
|
else startTransition(() => setError(isCorsOriginError(error) ? new Error(`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}` : ""}`, { cause: error }) : error));
|
|
39
39
|
});
|
|
40
|
-
const handleLiveEvent = useEffectEvent(
|
|
40
|
+
const handleLiveEvent = useEffectEvent((event) => {
|
|
41
41
|
switch (event.type) {
|
|
42
42
|
case "welcome":
|
|
43
|
-
setRefreshOnInterval(false);
|
|
44
|
-
if (onWelcome)
|
|
43
|
+
startTransition(() => setRefreshOnInterval(false));
|
|
44
|
+
if (onWelcome) startTransition(() => onWelcome(event, actionContext));
|
|
45
45
|
break;
|
|
46
46
|
case "message":
|
|
47
|
-
|
|
47
|
+
startTransition(() => action(event, actionContext));
|
|
48
48
|
break;
|
|
49
49
|
case "restart":
|
|
50
|
-
setRefreshOnInterval(false);
|
|
51
|
-
if (onRestart)
|
|
50
|
+
startTransition(() => setRefreshOnInterval(false));
|
|
51
|
+
if (onRestart) startTransition(() => onRestart(event, actionContext));
|
|
52
52
|
break;
|
|
53
53
|
case "reconnect":
|
|
54
|
-
setRefreshOnInterval(false);
|
|
55
|
-
if (onReconnect)
|
|
54
|
+
startTransition(() => setRefreshOnInterval(false));
|
|
55
|
+
if (onReconnect) startTransition(() => onReconnect(event, actionContext));
|
|
56
56
|
break;
|
|
57
57
|
case "goaway":
|
|
58
|
-
if (onGoAway)
|
|
58
|
+
if (onGoAway) startTransition(() => onGoAway(event, actionContext, (interval) => startTransition(() => setRefreshOnInterval(interval))));
|
|
59
59
|
else if (!onGoAway) handleError(new Error(`Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`, { cause: event }));
|
|
60
60
|
break;
|
|
61
61
|
default:
|
|
@@ -68,7 +68,7 @@ function SanityLive(props) {
|
|
|
68
68
|
includeDrafts: includeAllDocuments,
|
|
69
69
|
tag: requestTag
|
|
70
70
|
}).subscribe({
|
|
71
|
-
next:
|
|
71
|
+
next: handleLiveEvent,
|
|
72
72
|
error: handleError
|
|
73
73
|
});
|
|
74
74
|
return () => subscription.unsubscribe();
|
package/dist/SanityLive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport type {\n SanityLiveAction,\n SanityLiveActionContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n} from '#live/types'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeAllDocuments?: boolean\n requestTag: string\n\n action: SanityLiveAction\n onError: SanityLiveOnError | false | undefined\n onWelcome: SanityLiveOnWelcome | false | undefined\n onReconnect: SanityLiveOnReconnect | false | undefined\n onRestart: SanityLiveOnRestart | false | undefined\n onGoAway: SanityLiveOnGoaway | false | undefined\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeAllDocuments = false,\n action,\n onError,\n onWelcome = handleWelcome,\n onReconnect,\n onRestart,\n onGoAway = handleGoaway,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeAllDocuments} satisfies SanityLiveActionContext\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 const [error, setError] = useState<unknown>(null)\n if (error) {\n // Throw during render to bubble up to the nearest <ErrorBoundary>, if `onError` is provided we won't rethrow\n throw error\n }\n const handleError = useEffectEvent((error: unknown) => {\n if (onError) {\n void onError(error, actionContext)\n } else {\n startTransition(() =>\n setError(\n isCorsOriginError(error)\n ? new Error(\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.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n : error,\n ),\n )\n }\n })\n\n const handleLiveEvent = useEffectEvent(
|
|
1
|
+
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport type {\n SanityLiveAction,\n SanityLiveActionContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n} from '#live/types'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeAllDocuments?: boolean\n requestTag: string\n\n action: SanityLiveAction\n onError: SanityLiveOnError | false | undefined\n onWelcome: SanityLiveOnWelcome | false | undefined\n onReconnect: SanityLiveOnReconnect | false | undefined\n onRestart: SanityLiveOnRestart | false | undefined\n onGoAway: SanityLiveOnGoaway | false | undefined\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeAllDocuments = false,\n action,\n onError,\n onWelcome = handleWelcome,\n onReconnect,\n onRestart,\n onGoAway = handleGoaway,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeAllDocuments} satisfies SanityLiveActionContext\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 const [error, setError] = useState<unknown>(null)\n if (error) {\n // Throw during render to bubble up to the nearest <ErrorBoundary>, if `onError` is provided we won't rethrow\n throw error\n }\n const handleError = useEffectEvent((error: unknown) => {\n if (onError) {\n void onError(error, actionContext)\n } else {\n startTransition(() =>\n setError(\n isCorsOriginError(error)\n ? new Error(\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.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n : error,\n ),\n )\n }\n })\n\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\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\n if (onWelcome) {\n startTransition(() => onWelcome(event, actionContext))\n }\n break\n }\n case 'message': {\n startTransition(() => action(event, actionContext))\n break\n }\n case 'restart': {\n // Disable long polling when restart event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onRestart) {\n startTransition(() => onRestart(event, actionContext))\n }\n break\n }\n case 'reconnect': {\n // Disable long polling when reconnect event is received, this is a no-op if long polling is already disabled\n startTransition(() => setRefreshOnInterval(false))\n\n if (onReconnect) {\n startTransition(() => onReconnect(event, actionContext))\n }\n break\n }\n case 'goaway': {\n if (onGoAway) {\n startTransition(() =>\n onGoAway(event, actionContext, (interval) =>\n startTransition(() => setRefreshOnInterval(interval)),\n ),\n )\n } else if (!onGoAway) {\n handleError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n handleError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: includeAllDocuments, tag: requestTag})\n .subscribe({\n next: handleLiveEvent,\n error: handleError,\n })\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeAllDocuments])\n\n return (\n <>\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnInterval && Number.isFinite(refreshOnInterval) && refreshOnInterval > 0 && (\n <RefreshOnInterval interval={refreshOnInterval} />\n )}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n\nconst handleWelcome: SanityLiveOnWelcome = (_, {includeAllDocuments}) => {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive${includeAllDocuments ? ' includeAllDocuments' : ''}> is connected and listening for live events to ${includeAllDocuments ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n}\n\nconst handleGoaway: SanityLiveOnGoaway = (event, {includeAllDocuments}, setLongPollingInterval) => {\n const interval = 30_000\n console.warn(\n `<SanityLive${includeAllDocuments ? ' includeAllDocuments' : ''}> connection is closed after receiving a 'goaway' event, the server gave this reason:`,\n event.reason,\n `Content will now be refreshed every ${interval / 1_000} seconds`,\n )\n setLongPollingInterval(interval)\n}\n"],"mappings":";;;;;AAeA,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,oBAAoB,cAAc,OAAO,0BAAuB;AACtE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;AA8BxE,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,QACA,sBAAsB,OACtB,QACA,SACA,YAAY,eACZ,aACA,WACA,WAAW,cACX,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,MACrB,eACE;CACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,OAAO,qBACzE;CACF,MAAM,gBAAgB,EAAC,qBAAoB;CAE3C,MAAM,SAAS,cAEX,aAAa;EACX;EACA;EACA;EACA;EACA;EACA,2BAA2B;EAC3B;EACA,QAAQ;EACR;EACD,CAAC,EACJ;EAAC;EAAS;EAAY;EAAS;EAAW;EAAkB;EAAO;EAAmB,C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AAoB,CAAC;AAElD,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,qBAAqB,OAAO,SAAS,kBAAkB,IAAI,oBAAoB,KAC9E,oBAAC,mBAAA,EAAkB,UAAU,mBAAA,CAAqB;EAEnD,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc;AAIzB,MAAM,iBAAsC,GAAG,EAAC,0BAAyB;AAEvE,SAAQ,KACN,cAAc,sBAAsB,yBAAyB,GAAG,kDAAkD,sBAAsB,2EAA2E,sBACpN;;AAGH,MAAM,gBAAoC,OAAO,EAAC,uBAAsB,2BAA2B;CACjG,MAAM,WAAW;AACjB,SAAQ,KACN,cAAc,sBAAsB,yBAAyB,GAAG,wFAChE,MAAM,QACN,uCAAuC,WAAW,IAAM,UACzD;AACD,wBAAuB,SAAS"}
|
|
@@ -20,11 +20,12 @@ function defineLive(config) {
|
|
|
20
20
|
});
|
|
21
21
|
const { token: originalToken, perspective: originalPerspective = "published" } = client.config();
|
|
22
22
|
const studioUrlDefined = typeof client.config().stega.studioUrl !== "undefined";
|
|
23
|
-
const sanityFetch = async function sanityFetch({ query, params = {}, stega: _stega, tags = [
|
|
23
|
+
const sanityFetch = async function sanityFetch({ query, params = {}, stega: _stega, tags = [], perspective: _perspective, tag, requestTag = tag ?? "next-loader.fetch" }) {
|
|
24
24
|
const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled);
|
|
25
25
|
const perspective = _perspective ?? await resolveCookiePerspective(originalPerspective === "raw" ? "published" : originalPerspective);
|
|
26
26
|
const useCdn = perspective === "published";
|
|
27
27
|
const revalidate = false;
|
|
28
|
+
const cacheTagPrefix = perspective === "published" ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX;
|
|
28
29
|
const { syncTags } = await client.fetch(query, await params, {
|
|
29
30
|
filterResponse: false,
|
|
30
31
|
perspective,
|
|
@@ -32,13 +33,13 @@ function defineLive(config) {
|
|
|
32
33
|
returnQuery: false,
|
|
33
34
|
next: {
|
|
34
35
|
revalidate,
|
|
35
|
-
tags: [...tags, "
|
|
36
|
+
tags: [...tags, "fetch-sync-tags"].map((tag) => `${cacheTagPrefix}${tag}`)
|
|
36
37
|
},
|
|
37
38
|
useCdn,
|
|
38
39
|
cacheMode: useCdn ? "noStale" : void 0,
|
|
39
40
|
tag: [requestTag, "fetch-sync-tags"].filter(Boolean).join(".")
|
|
40
41
|
});
|
|
41
|
-
const cacheTags = [...tags, ...syncTags?.map((tag) => `${
|
|
42
|
+
const cacheTags = [...tags, ...syncTags?.map((tag) => `${cacheTagPrefix}${tag}`) || []];
|
|
42
43
|
const { result, resultSourceMap } = await client.fetch(query, await params, {
|
|
43
44
|
filterResponse: false,
|
|
44
45
|
perspective,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import {type ClientPerspective, type QueryParams} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nexport function defineLive(config: DefineLiveOptions): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\n const {client: _client, serverToken, browserToken, stega: stegaEnabled = true} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken, perspective: originalPerspective = 'published'} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = [
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import {type ClientPerspective, type QueryParams} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nexport function defineLive(config: DefineLiveOptions): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\n const {client: _client, serverToken, browserToken, stega: stegaEnabled = true} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken, perspective: originalPerspective = 'published'} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = [],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective =\n _perspective ??\n (await resolveCookiePerspective(\n originalPerspective === 'raw' ? 'published' : originalPerspective,\n ))\n const useCdn = perspective === 'published'\n const revalidate = false\n const cacheTagPrefix =\n perspective === 'published' ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {revalidate, tags: [...tags, 'fetch-sync-tags'].map((tag) => `${cacheTagPrefix}${tag}`)},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `${cacheTagPrefix}${tag}`) || [])]\n\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate, tags: cacheTags},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedLiveProps> = async function SanityLive(props) {\n const {\n includeAllDocuments = (await draftMode()).isEnabled,\n action = actionUpdateTags,\n onReconnect = actionRefresh,\n onRestart = actionRefresh,\n\n onWelcome = false,\n onError = false,\n onGoAway = false,\n\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const shouldIncludeAllDocuments = typeof browserToken === 'string' && includeAllDocuments\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: shouldIncludeAllDocuments ? browserToken : undefined,\n }}\n includeAllDocuments={shouldIncludeAllDocuments}\n action={action}\n onReconnect={onReconnect}\n onRestart={onRestart}\n onWelcome={onWelcome}\n onError={onError}\n onGoAway={onGoAway}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch,\n SanityLive,\n }\n}\n\nasync function resolveCookiePerspective(\n fallback: Exclude<ClientPerspective, 'raw'>,\n): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await c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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "13.0.0-cache-components.
|
|
3
|
+
"version": "13.0.0-cache-components.29",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@portabletext/react": "^6.0.3",
|
|
65
|
-
"@sanity/client": "^7.
|
|
65
|
+
"@sanity/client": "^7.20.0",
|
|
66
66
|
"@sanity/comlink": "^4.0.1",
|
|
67
67
|
"@sanity/presentation-comlink": "^2.0.1",
|
|
68
68
|
"@sanity/preview-url-secret": "^4.0.4",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@vitejs/plugin-react": "^5.2.0",
|
|
83
83
|
"@vitest/coverage-v8": "^4.1.0",
|
|
84
84
|
"js-yaml": "^4.1.1",
|
|
85
|
-
"next": "16.2.1-canary.
|
|
85
|
+
"next": "16.2.1-canary.5",
|
|
86
86
|
"publint": "^0.3.18",
|
|
87
87
|
"react": "^19.2.4",
|
|
88
88
|
"react-dom": "^19.2.4",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"vitest-package-exports": "^1.2.0"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@sanity/client": "^7.
|
|
97
|
+
"@sanity/client": "^7.20.0",
|
|
98
98
|
"next": "^16.0.0-0",
|
|
99
99
|
"react": "^19.2.3",
|
|
100
100
|
"react-dom": "^19.2.3",
|