Token导航 LogoToken导航

Agent Skill · 前端设计

sanity-live-cache-components(健全的实时缓存组件)

sanity-live-cache-components 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

sanity-live-cache-components 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为操作浏览器;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 7,374。

总安装 380周安装 16GitHub Stars 949下载 133核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:sanity-live-cache-components(健全的实时缓存组件)
来源仓库:https://github.com/sanity-io/next-sanity
仓库路径:skills/sanity-live-cache-components
安装命令:
npx skills add https://github.com/sanity-io/next-sanity --skill sanity-live-cache-components
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/sanity-io/next-sanity --skill sanity-live-cache-components

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

sanity-live-cache-components 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。

通过 npx skills add 命令从指定 GitHub 仓库安装,需结合原始 README 确认具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。当前分类为前端设计,暂无更多功能说明。

来源仓库内路径:skills/sanity-live-cache-components

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/sanity-io/next-sanity --skill sanity-live-cach…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要操作浏览器,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

sanity-live-cache-components 怎么安装?

在终端执行 npx skills add https://github.com/sanity-io/next-sanity --skill sanity-live-cache-componen…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

sanity-live-cache-components 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

sanity-live-cache-components 需要什么权限?

权限级别是操作浏览器。该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

sanity-live-cache-components 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

sanity-live-cache-components 用的人多吗?

公开数据是累计安装 380 次,近一周安装 16 次,下载 133 次,GitHub 949 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

sanity-live-cache-components 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
sanity-live-cache-components

健全的实时缓存组件 · 本页

380949操作浏览器未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Sanity Live + Cache Components (next-sanity@cache-components)

Use next-sanity@cache-components with Next.js 16+ cacheComponents: true to get Partial Prerendering with Sanity Live. This replaces the automatic draftMode() behavior with explicit perspective, stega, and includeDrafts passing.

Canary release -- not yet stable, may have breaking changes in minor/patch releases.

1. Install

npm install next-sanity@cache-components --save-exact

Requires next@16+.


2. Configure next.config.ts

// next.config.ts
import type {NextConfig} from 'next'
import {sanity} from 'next-sanity/live/cache-life'

const nextConfig: NextConfig = {
  cacheComponents: true,
  cacheLife: {sanity},
}

export default nextConfig

When is cacheLife('sanity') needed?

sanityFetch calls cacheLife internally -- 'use cache' boundaries that call sanityFetch do not need cacheLife('sanity').

The sanity preset is only needed for 'use cache' boundaries that do not call sanityFetch but should match Sanity's revalidation timing (e.g. a cached layout shell). Without it, those boundaries default to revalidating every 15 minutes, which is unnecessary since Sanity Live handles on-demand revalidation.

If the app has no such boundaries, the cacheLife: {sanity} config can be omitted entirely.


3. Configure defineLive

strict: true (when using Visual Editing)

Set strict: true when the app uses Visual Editing in Sanity Studio's Presentation Tool -- especially for perspective switching with Content Releases. This ensures the app correctly handles different perspectives by making perspective, stega, and includeDrafts required at every call site (type-enforced).

How to detect: if the app renders <VisualEditing /> from next-sanity/visual-editing anywhere (typically in the root layout), it uses Visual Editing and should set strict: true.

If the app does not use Visual Editing, strict can be omitted -- the defaults (perspective: 'published', stega: false, includeDrafts: false) are sufficient.

// src/sanity/lib/live.ts

import {createClient, type QueryParams} from 'next-sanity'
import {defineLive, resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
import {cookies, draftMode} from 'next/headers'

const client = createClient({
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
  useCdn: true,
  apiVersion: 'v2025-03-04',
  stega: {studioUrl: '/studio'},
})

const token = process.env.SANITY_API_READ_TOKEN
if (!token) {
  throw new Error('Missing SANITY_API_READ_TOKEN')
}

export const {sanityFetch, SanityLive} = defineLive({
  client,
  serverToken: token,
  browserToken: token,
  strict: true,
})

When strict: true:

  • sanityFetch() requires explicit perspective and stega
  • <SanityLive> requires explicit includeDrafts prop
  • Missing values produce type errors and runtime errors

4. getDynamicFetchOptions Helper

Export this from the same live.ts file. It encapsulates the draftMode() and cookies() calls that cannot be used inside 'use cache' boundaries:

// src/sanity/lib/live.ts (continued)

export interface DynamicFetchOptions {
  perspective: LivePerspective
  stega: boolean
  isDraftMode: boolean
}

export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {
  const {isEnabled: isDraftMode} = await draftMode()
  if (!isDraftMode) {
    return {perspective: 'published', stega: false, isDraftMode}
  }

  const jar = await cookies()
  const perspective = await resolvePerspectiveFromCookies({cookies: jar})
  return {perspective: perspective ?? 'drafts', stega: true, isDraftMode}
}

Call this at the top level only -- in layout.tsx or page.tsx. Never call it deep in the component tree (see Prop-Drilling).


5. sanityFetchStaticParams Helper

Export a helper for generateStaticParams to avoid repeating boilerplate:

// src/sanity/lib/live.ts (continued)

export async function sanityFetchStaticParams<const QueryString extends string>({
  query,
  params = {},
}: {
  query: QueryString
  params?: QueryParams
}) {
  return client.fetch(query, params, {perspective: 'published', stega: false, useCdn: true})
}

Usage:

export async function generateStaticParams() {
  return sanityFetchStaticParams({query: slugsByTypeQuery, params: {type: 'page'}})
}

6. Prop-Drilling

Resolve isDraftMode, perspective, and stega once at the top level and prop-drill them down. This is critical:

  1. getDynamicFetchOptions() calls draftMode() -- a dynamic API. Calling it deep in the tree shrinks the static shell and may cause unexpected Suspense fallbacks.
  2. In draft mode, getDynamicFetchOptions() calls cookies() -- the calling component must be wrapped in <Suspense>. This complexity belongs at the top level, not in every <Navbar> or <Footer>.

The three-layer pattern (Page -> Dynamic -> Cached) should only exist in layout.tsx and page.tsx. Shared components receive resolved values as props and go straight to their cached layer.


7. The Three-Layer Component Pattern

This is the core architecture for every route.

Structure

Page/Layout (Layer 1)
  ├── NOT draft mode → <CachedX perspective="published" stega={false} />  (no Suspense)
  └── draft mode → <Suspense fallback={...}>
                      <DynamicX params={params} />  (Layer 2)
                        └── <CachedX slug={slug} perspective={p} stega={s} />  (Layer 3)

Layer 1: Page Component

Calls draftMode() and branches:

export default async function Page({params}: {params: Promise<{slug: string}>}) {
  const {isEnabled: isDraftMode} = await draftMode()
  if (isDraftMode) {
    return (
      <Suspense
        fallback={
          <Template>
            <LoadingSkeleton />
          </Template>
        }
      >
        <DynamicPage params={params} />
      </Suspense>
    )
  }
  const {slug} = await params
  return <CachedPage slug={slug} perspective="published" stega={false} />
}
  • Not in draft mode: await params, render cached directly -- no Suspense, maximizes static shell
  • In draft mode: pass the params Promise to <DynamicX> without awaiting -- let it resolve inside the Suspense boundary so the static shell streams immediately

Layer 2: Dynamic Component

Only rendered in the draft mode path. Resolves all async values:

async function DynamicPage({params}: {params: Promise<{slug: string}>}) {
  const {slug} = await params
  const {perspective, stega} = await getDynamicFetchOptions()
  return <CachedPage slug={slug} perspective={perspective} stega={stega} />
}

Layer 3: Cached Component

Has 'use cache' and only receives plain, serializable props:

async function CachedPage({
  slug,
  perspective,
  stega,
}: {slug: string} & Pick<DynamicFetchOptions, 'perspective' | 'stega'>) {
  'use cache'
  const {data} = await sanityFetch({
    query: PAGE_QUERY,
    params: {slug},
    perspective,
    stega,
  })

  return (
    <Template>
      <h1>{data?.title}</h1>
    </Template>
  )
}

Rules

  • Never call draftMode(), cookies(), or headers() inside 'use cache'
  • notFound() can be called inside 'use cache' -- move it there and remove the old if (!data &&!isDraftMode) notFound() guard. In draft mode the Suspense boundary handles the case where a document doesn't exist yet.
  • Never wrap cached components in <Suspense> outside draft mode -- unnecessary streaming boundaries shrink the static shell
  • Always pass plain values (slug: string) to cached components, not Promises
  • Always pass explicit perspective="published" and stega={false} in the non-draft path -- never omit these or make them optional. Every call to a cached component or sanityFetch must have explicit values so cache keys are consistent and stable in production. A mixture of undefined and "published" would create duplicate cache entries for the same content.
  • perspective and stega act as cache keys -- published and draft content get separate cache entries automatically

8. <SanityLive> -- Pass includeDrafts

With cacheComponents: true, <SanityLive> defaults includeDrafts to false and does not read draftMode() internally. You must pass it explicitly:

<SanityLive includeDrafts={isDraftMode} />

9. Layout Example

The root layout resolves draftMode() once and wraps individual dynamic components in their own Suspense boundaries -- no <DynamicLayout> wrapper needed:

// src/app/(site)/layout.tsx

import {draftMode} from 'next/headers'
import {VisualEditing} from 'next-sanity/visual-editing'
import {getDynamicFetchOptions, SanityLive} from '@/sanity/lib/live'
import {Navbar} from '@/components/Navbar'
import {Footer} from '@/components/Footer'
import {Suspense} from 'react'

export default async function SiteLayout({children}: {children: React.ReactNode}) {
  const {isEnabled: isDraftMode} = await draftMode()
  return <CachedLayout isDraftMode={isDraftMode}>{children}</CachedLayout>
}

function CachedLayout({children, isDraftMode}: {children: React.ReactNode; isDraftMode: boolean}) {
  return (
    <div className="flex min-h-screen flex-col">
      {isDraftMode ? (
        <Suspense fallback={<Navbar perspective="published" stega={false} />}>
          <DynamicNavbar />
        </Suspense>
      ) : (
        <Navbar perspective="published" stega={false} />
      )}

      <main>{children}</main>

      {isDraftMode ? (
        <Suspense fallback={<Footer perspective="published" stega={false} />}>
          <DynamicFooter />
        </Suspense>
      ) : (
        <Footer perspective="published" stega={false} />
      )}

      <SanityLive includeDrafts={isDraftMode} />
      {isDraftMode && <VisualEditing />}
    </div>
  )
}

async function DynamicNavbar() {
  const {perspective, stega} = await getDynamicFetchOptions()
  return <Navbar perspective={perspective} stega={stega} />
}

async function DynamicFooter() {
  const {perspective, stega} = await getDynamicFetchOptions()
  return <Footer perspective={perspective} stega={stega} />
}

Key points:

  • draftMode() is called once in SiteLayout and the result is passed to <CachedLayout> -- calling draftMode() in a layout does not prevent the layout from being included in the static shell. The <CachedLayout> component ensures the shell HTML is still prerendered.
  • Each dynamic component (<Navbar>, <Footer>) gets its own <Suspense> boundary with the published cached version as fallback -- users see cached content while draft content streams in
  • <DynamicNavbar> and <DynamicFooter> are thin wrappers defined inline that call getDynamicFetchOptions() and pass the result as props
  • The static shell (<div>, <main>, etc.) is never wrapped in Suspense

10. Shared Component Example (Navbar)

With prop-drilling, shared components become simple -- no draftMode(), no getDynamicFetchOptions(), no internal Suspense. The layout handles all of that. The component just receives props and renders cached:

// src/components/Navbar.tsx

import {sanityFetch, type DynamicFetchOptions} from '@/sanity/lib/live'
import {settingsQuery} from '@/sanity/lib/queries'

export async function Navbar({
  perspective,
  stega,
}: Pick<DynamicFetchOptions, 'perspective' | 'stega'>) {
  'use cache'
  const {data} = await sanityFetch({query: settingsQuery, perspective, stega})
  return (
    <header className="sticky top-0 z-10 flex items-center gap-4 bg-white/80 px-4 py-4 backdrop-blur">
      {data?.menuItems?.map((item) => (
        <a key={item._key} href={item.slug}>
          {item.title}
        </a>
      ))}
    </header>
  )
}

The layout wraps <Navbar> in <Suspense> when in draft mode (see Layout Example). The Navbar itself doesn't know or care about draft mode.


11. Page Example (Dynamic Route)

// src/app/(site)/[slug]/page.tsx

import {draftMode} from 'next/headers'
import {defineQuery} from 'next-sanity'
import {
  getDynamicFetchOptions,
  sanityFetch,
  sanityFetchStaticParams,
  type DynamicFetchOptions,
} from '@/sanity/lib/live'
import {Suspense} from 'react'
import type {Metadata, ResolvingMetadata} from 'next'

const PAGE_QUERY = defineQuery(
  `*[_type == "page" && slug.current == $slug][0]{_id, _type, title, body}`,
)
const SLUGS_QUERY = defineQuery(`*[_type == $type && defined(slug.current)]{"slug": slug.current}`)

type Props = {params: Promise<{slug: string}>}

export async function generateStaticParams() {
  return sanityFetchStaticParams({query: SLUGS_QUERY, params: {type: 'page'}})
}

// --- generateMetadata ---

export async function generateMetadata(
  {params}: Props,
  parent: ResolvingMetadata,
): Promise<Metadata> {
  const {slug} = await params
  const {perspective} = await getDynamicFetchOptions()
  const data = await cachedPageMetadata({slug, perspective})
  return {
    title: data?.title,
  }
}

async function cachedPageMetadata({
  slug,
  perspective,
}: {slug: string} & Pick<DynamicFetchOptions, 'perspective'>) {
  'use cache'
  const {data} = await sanityFetch({
    query: PAGE_QUERY,
    params: {slug},
    perspective,
    stega: false,
  })
  return data
}

// --- Page ---

export default async function PageRoute({params}: Props) {
  const {isEnabled: isDraftMode} = await draftMode()
  if (isDraftMode) {
    return (
      <Suspense fallback={<Template>Loading...</Template>}>
        <DynamicPageRoute params={params} />
      </Suspense>
    )
  }
  const {slug} = await params
  return <CachedPageRoute slug={slug} perspective="published" stega={false} />
}

async function DynamicPageRoute({params}: Props) {
  const {slug} = await params
  const {perspective, stega} = await getDynamicFetchOptions()
  return <CachedPageRoute slug={slug} perspective={perspective} stega={stega} />
}

async function CachedPageRoute({
  slug,
  perspective,
  stega,
}: {slug: string} & Pick<DynamicFetchOptions, 'perspective' | 'stega'>) {
  'use cache'
  const {data} = await sanityFetch({query: PAGE_QUERY, params: {slug}, perspective, stega})
  return (
    <Template>
      <h1>{data?.title}</h1>
    </Template>
  )
}

function Template({children}: {children: React.ReactNode}) {
  return <div className="space-y-6">{children}</div>
}

12. generateMetadata Rules

  • Always resolve perspective via getDynamicFetchOptions() -- this supports published content in production, drafts in draft mode, and Content Releases perspective switching in Presentation Tool
  • Always hard-code stega: false -- stega encoding must never appear in titles, descriptions, or OG metadata
  • Delegate to a separate cachedMetadata function with 'use cache' -- do NOT put 'use cache' on generateMetadata itself since it needs to call getDynamicFetchOptions()
  • If a query is shared between generateMetadata and a cached component (where stega may be true), you must split into a separate cachedMetadata function. Never reuse a shared cached function that passes stega through.

13. Suspense Fallback Strategy

  • Preferred: meaningful loading UI using a sync Template component that mirrors the cached component's layout. Better experience in Presentation Tool during Visual Editing. These fallbacks are only visible in draft mode (never in production), so they don't need high-quality designs or pixel-perfect skeletons -- a simple "Loading..." text inside the same layout shell is fine. CLS/web vitals are not affected since production never hits these Suspense boundaries.
  • Discouraged: using <CachedX perspective="published" stega={false} /> as the Suspense fallback. While technically possible, this causes problems:

- Triggers warnings in next dev - Shows published content briefly before draft content streams in -- confusing for editors who don't realize they're in a loading state - Can cause layout shift when the draft content replaces the published content - If no meaningful skeleton exists, use a simple placeholder (e.g. <Template>Loading...</Template>) or fallback={null} rather than stale content

  • Extract a Template component for the static HTML shell. Reuse in both the Suspense fallback and the cached component output.

14. Key Differences from cacheComponents: false

  • sanityFetch no longer reads draftMode() automatically -- pass perspective and stega explicitly
  • <SanityLive> no longer reads draftMode() automatically -- pass includeDrafts explicitly
  • sanityFetch calls cacheTag() and cacheLife() internally -- no manual cache tag management
  • Use sanityFetchStaticParams (or client.fetch() directly) for generateStaticParams -- not sanityFetch
  • Remove export const dynamic = 'force-static' -- not needed with cacheComponents
  • Move notFound() inside the cached component -- remove old if (!data &&!isDraftMode) notFound() guards. In draft mode the Suspense boundary handles documents that don't exist yet

Sources:

平台分布

Codex

34.76%
按下载量换算46

Claude

29.72%
按下载量换算40

Cursor

17.59%
按下载量换算23

Gemini CLI

10.78%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills