Skip to content

feat: persist Content Variants and pass variant through fetches - #1532

Open
stipsan wants to merge 5 commits into
mainfrom
feat/visual-editing-variants
Open

feat: persist Content Variants and pass variant through fetches#1532
stipsan wants to merge 5 commits into
mainfrom
feat/visual-editing-variants

Conversation

@stipsan

@stipsan stipsan commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Persist Presentation perspective and Content Variants to cookies (preview enable/disable, comlink loader/perspective). Overlay onPerspectiveChange / onVariantChange stay private — they always write useSanityPerspective / useSanityVariant, with no nuxt.config hooks.
  • Pass variant through resolveFetchOptions and useSanityQuery (cookie by default; queryOptions.variant wins). Bump @sanity/core-loader to ^2.1.4 so live loaders thread variants.
  • Document useSanityPreviewVariant and the beta opt-ins (Studio beta.variants.enabled, Nuxt apiVersion: 'X'). Module default apiVersion is unchanged.

Stacked on #1530. After that merges, retarget this PR at main.

Test plan

  • CI: unit tests, types, lint
  • Enable preview from Presentation and confirm perspective (and variant, if selected) cookies are set; disable clears them
  • Change perspective/variant in Presentation and confirm cookies update
  • useSanityQuery sends variant once the cookie is set; queryOptions.variant overrides the cookie
  • Playground preview banner shows the selected variant
  • visualEditing.onPerspectiveChange / onVariantChange are not module options

@stipsan
stipsan requested a review from danielroe as a code owner August 13, 2026 15:00
@pkg-pr-new

pkg-pr-new Bot commented Aug 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 2d49e04

@stipsan
stipsan changed the base branch from feat/visual-editing-perspective to feat/visual-editing-standalone-v2 August 17, 2026 12:12
@sanity/visual-editing-standalone@2 no longer injects CSS, so import
styles.css next to enableVisualEditing() to keep overlay styles loading.

Co-authored-by: Cursor <cursoragent@cursor.com>
@stipsan
stipsan force-pushed the feat/visual-editing-variants branch from 7d2ff6b to 5186461 Compare August 17, 2026 12:15
Keep overlay onPerspectiveChange and onVariantChange private so cookies
stay in sync without public nuxt.config hooks.

Co-authored-by: Cursor <cursoragent@cursor.com>
@stipsan
stipsan force-pushed the feat/visual-editing-variants branch from 5186461 to da0d186 Compare August 17, 2026 12:21
stipsan and others added 2 commits August 19, 2026 00:10
Keep @sanity/visual-editing-standalone at ^2.0.1 after main landed ^2.0.0.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ting-variants

Co-authored-by: Cursor <cursoragent@cursor.com>
Base automatically changed from feat/visual-editing-standalone-v2 to main August 18, 2026 22:43
Keep private onPerspectiveChange/onVariantChange after #1530 landed.

Co-authored-by: Cursor <cursoragent@cursor.com>
@netlify

netlify Bot commented Aug 18, 2026

Copy link
Copy Markdown

Deploy Preview for nuxt-sanity-module ready!

Name Link
🔨 Latest commit 2d49e04
🔍 Latest deploy log https://app.netlify.com/projects/nuxt-sanity-module/deploys/6a84e12df9b1030008d41244
😎 Deploy Preview https://deploy-preview-1532--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.

if (studioPreviewPerspective) {
setCookie(event, perspectiveCookieName, studioPreviewPerspective, cookieOptions)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are deleting the cookie with studioPreviewVariant is not present, but we are not doing that for studioPreviewPerspective do you need here also this? ?

Suggested change
else {
deleteCookie(event, perspectiveCookieName, cookieOptions)
}

const queryKey = _key || 'sanity-' + hash(query + (params ? JSON.stringify(params) : ''))

const perspective = useSanityPerspective(perspectiveOption, clientConfig.perspective)
const variant = useSanityVariant()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we aim here also to preserve the clientConfig.variant? Following what perspective is doing:
const perspective = useSanityPerspective(perspectiveOption, clientConfig.perspective)

@pedrobonamin pedrobonamin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pr looks good, added some comments that are not blocking, would appreciate your thoughts.
Thanks!

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.

2 participants