Skip to content

feat: make previewCookieName configurable and add useSanityPreviewCookie - #1511

Draft
parion wants to merge 1 commit into
nuxt-modules:mainfrom
parion:feat/configurable-preview-cookie-name
Draft

feat: make previewCookieName configurable and add useSanityPreviewCookie#1511
parion wants to merge 1 commit into
nuxt-modules:mainfrom
parion:feat/configurable-preview-cookie-name

Conversation

@parion

@parion parion commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves #1431. Makes the preview mode cookie name configurable via a new visualEditing.previewCookieName option, and adds a useSanityPreviewCookie composable so apps can read the cookie (e.g. to protect routes when preview mode is not active).

Changes

  • visualEditing.previewCookieName option (default sanity-preview-id) is threaded through the public runtime config, mirroring the existing keepStegaOnCopy option.
  • All preview cookie consumers now use the configured name with a fallback to the default constant:
    • server/routes/preview/enable.ts
    • server/routes/preview/disable.ts
    • server/routes/preview/proxy.ts
    • plugins/visual-editing.server.ts
  • New useSanityPreviewCookie composable reads the cookie value via useSanityConfig(); auto-imported and exported from the composables barrel when visual editing is configured.
  • Types updated in SanityPublicRuntimeConfig and SanityResolvedConfig.
  • Docs added for the option + composable in the visual editing guide.

Tests

  • New test/unit/useSanityPreviewCookie.test.ts covering:
    • default cookie name when not configured
    • configured cookie name
    • returned ref passthrough
  • Full suite green: 176 tests across unit/e2e/nuxt projects, plus test:types and lint.

Notes

The cookie is httpOnly, so useSanityPreviewCookie reads server-side (SSR/middleware), which is where route protection happens. The issue author's suggested usePreviewCookie() naming was adapted to useSanityPreviewCookie to match the module's composable conventions.

@parion
parion requested a review from danielroe as a code owner August 3, 2026 04:02
@netlify

netlify Bot commented Aug 3, 2026

Copy link
Copy Markdown

Deploy Preview for nuxt-sanity-module ready!

Name Link
🔨 Latest commit 7cc52ee
🔍 Latest deploy log https://app.netlify.com/projects/nuxt-sanity-module/deploys/6a7012f3db5ca50008babd98
😎 Deploy Preview https://deploy-preview-1511--nuxt-sanity-module.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxtjs/sanity@1511

commit: c645a18

@parion
parion marked this pull request as draft August 3, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make previewCookieName configurable

1 participant