Socket
Socket
Sign inDemoInstall

@sanity/preview-kit

Package Overview
Dependencies
Maintainers
35
Versions
229
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/preview-kit - npm Package Compare versions

Comparing version 1.2.0-add-type-allowlist.2 to 1.2.0

4

dist/index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc