@sanity/preview-kit
Advanced tools
Comparing version 1.2.0-add-type-allowlist.2 to 1.2.0
@@ -33,3 +33,3 @@ import type { Config } from '@sanity/groq-store' | ||
checkAuth, | ||
allowTypes, | ||
includeTypes, | ||
}: _PreviewConfig) => UsePreview | ||
@@ -106,3 +106,3 @@ | ||
| 'subscriptionThrottleMs' | ||
| 'allowTypes' | ||
| 'includeTypes' | ||
> { | ||
@@ -109,0 +109,0 @@ /** |
@@ -39,3 +39,3 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
checkAuth, | ||
allowTypes | ||
includeTypes | ||
} = _ref; | ||
@@ -68,3 +68,3 @@ if (!projectId) { | ||
subscriptionThrottleMs, | ||
allowTypes, | ||
includeTypes, | ||
token: token === null ? void 0 : token, | ||
@@ -71,0 +71,0 @@ EventSource: token === null ? void 0 : importEventSourcePolyfill(), |
{ | ||
"name": "@sanity/preview-kit", | ||
"version": "1.2.0-add-type-allowlist.2", | ||
"version": "1.2.0", | ||
"description": "General purpose live previews, like next-sanity", | ||
@@ -66,6 +66,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@sanity/groq-store": "1.1.0-add-type-allowlist.1", | ||
"@sanity/groq-store": "^1.1.0", | ||
"@types/event-source-polyfill": "^1.0.0", | ||
"event-source-polyfill": "^1.0.31", | ||
"suspend-react": "^0.0.8" | ||
"suspend-react": "0.0.8" | ||
}, | ||
@@ -79,3 +79,3 @@ "devDependencies": { | ||
"@types/react": "^18.0.25", | ||
"@typescript-eslint/eslint-plugin": "^5.42.1", | ||
"@typescript-eslint/eslint-plugin": "^5.43.0", | ||
"bulma": "^0.9.4", | ||
@@ -95,2 +95,3 @@ "eslint": "^8.27.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^4.8.4" | ||
@@ -97,0 +98,0 @@ }, |
@@ -20,2 +20,47 @@ # @sanity/preview-kit | ||
You create a `usePreview` hook using `definePreview` | ||
```tsx | ||
import { definePreview } from '@sanity/preview-kit' | ||
const usePreview = definePreview({ projectId, dataset }) | ||
``` | ||
If you want to declare the config in a separate file, and have full typings, you can import `PreviewConfig`: | ||
```tsx | ||
import type { PreviewConfig } from '@sanity/preview-kit' | ||
export const previewConfig: PreviewConfig = { | ||
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID, | ||
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET, | ||
// The limit on number of documents, to prevent using too much memory unexpectedly | ||
// It's 3000 by default, increase or decrease as needed and use `includeTypes` to further optimize the performance | ||
documentLimit: 10000, | ||
// Optional allow list filter for document types. You can use this to limit the amount of documents by declaring the types you want to sync. Note that since you're fetching a subset of your dataset, queries that works against your Content Lake might not work against the local groq-store. | ||
includeTypes: ['post', 'page', 'product', 'sanity.imageAsset'], | ||
} | ||
``` | ||
The component that calls `usePreview` needs to be wrapped in a `Suspense` boundary as it will ["suspend"](https://reactjs.org/docs/react-api.html#reactsuspense) until the `@sanity/groq-store` is done loading your dataset and ready to resolve your queries. This component should also only be rendered in the browser and not on the server. If you use `PreviewSuspense` then both gotchas are covered for you: | ||
```tsx | ||
import { definePreview, PreviewSuspense } from '@sanity/preview-kit' | ||
const usePreview = definePreview({ projectId, dataset }) | ||
function PreviewComponent() { | ||
const data = usePreview(null, `*[]`) | ||
} | ||
export default function Page() { | ||
if (preview) { | ||
return ( | ||
<PreviewSuspense fallback="Loading..."> | ||
<PreviewComponent /> | ||
</PreviewSuspense> | ||
) | ||
} | ||
} | ||
``` | ||
### Next 12 Preview Mode, cookie auth only | ||
@@ -22,0 +67,0 @@ |
@@ -77,3 +77,3 @@ import type { Config, GroqStore } from '@sanity/groq-store' | ||
checkAuth, | ||
allowTypes, | ||
includeTypes, | ||
}: _PreviewConfig): UsePreview => { | ||
@@ -136,3 +136,3 @@ if (!projectId) { | ||
subscriptionThrottleMs, | ||
allowTypes, | ||
includeTypes, | ||
token: token === null ? undefined : token, | ||
@@ -199,3 +199,3 @@ // Lazy load the huge `event-source-polyfill`, but only if a token is specified | ||
| 'subscriptionThrottleMs' | ||
| 'allowTypes' | ||
| 'includeTypes' | ||
> { | ||
@@ -202,0 +202,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
72970
0
231
23
+ Added@sanity/client@6.21.3(transitive)
+ Added@sanity/eventsource@5.0.2(transitive)
+ Added@sanity/groq-store@1.1.5(transitive)
+ Added@sanity/types@3.57.4(transitive)
+ Added@types/eventsource@1.1.15(transitive)
+ Added@types/follow-redirects@1.14.4(transitive)
+ Added@types/node@22.5.5(transitive)
+ Added@types/progress-stream@2.0.5(transitive)
+ Added@types/react@18.3.8(transitive)
+ Addeddecompress-response@7.0.0(transitive)
+ Addedget-it@8.6.5(transitive)
+ Addedgroq@3.57.4(transitive)
+ Addedis-retry-allowed@2.2.0(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedtslib@2.7.0(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@sanity/client@3.4.1(transitive)
- Removed@sanity/color@2.2.5(transitive)
- Removed@sanity/eventsource@4.1.1(transitive)
- Removed@sanity/groq-store@1.1.0-add-type-allowlist.1(transitive)
- Removed@sanity/timed-out@4.0.2(transitive)
- Removed@sanity/types@2.36.2(transitive)
- Removed@types/react@17.0.82(transitive)
- Removed@types/scheduler@0.16.8(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removedcreate-error-class@3.0.2(transitive)
- Removeddebug@2.6.9(transitive)
- Removedform-urlencoded@2.0.9(transitive)
- Removedfrom2@2.3.0(transitive)
- Removedget-it@6.1.1(transitive)
- Removedgroq@2.33.2(transitive)
- Removedinto-stream@3.1.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisobject@3.0.1(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedms@2.0.0(transitive)
- Removednano-pubsub@1.0.2(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedp-is-promise@1.1.0(transitive)
- Removedparse-headers@2.0.5(transitive)
- Removedquerystringify@2.2.0(transitive)
- Removedrequires-port@1.0.0(transitive)
- Removedrxjs@6.6.7(transitive)
- Removedsame-origin@0.1.1(transitive)
- Removedtslib@1.14.1(transitive)
- Removedurl-parse@1.5.10(transitive)
Updated@sanity/groq-store@^1.1.0
Updatedsuspend-react@0.0.8